Check if a page belongs to a bundle

I wonder if there is currently a way to test if a given page belongs to a bundle.

I think this has been discussed and potential method might have been implemented but I cannot find it in the doc and any issue search in the repo has failed me :frowning:

I need to pass a Page Object to a partial, and depending if given page is part of a bundle or not, take an action.

Thanks!

One thought: check if .File.BaseFileName is index or something else.

Yep, I use that:

Note that {{ with .File }} is now needed… IIRC using .File.BaseFileName directly gave some error starting some 0.5x.y version.


Update

using .File.BaseFileName directly gave some error starting some 0.5x.y version.

It was Hugo v0.55.0 (ref)

2 Likes

Nice @kaushalmodi.

Also note: that warning won’t be shown as long as the page being checked has a non nil .File (at least that’s the case for me here).

if .Parent.BundleType

Or something…

There is an open issue about documenting .Page.BundleType

It can have either leaf or branch as values or an empty string as per commit: https://github.com/gohugoio/hugo/commit/402f6788ee955ad2aace84e8fba1625db7b356d9

2 Likes

Thank you all! I should have looked in the docs repo!

Will do next time!