How do I determine if my .Page has a bundle or if I'm a naked page?

I’ve read the documentation and threads here about the difference between slug/index.md and slug.md, where the later does not have access to page bundled resources. I understand what the limitations of bundle-less pages.

Is there a proper way to tell if my page has a bundle or is bundle-less?

I have a situation (a photo gallery) where images could be shared across sibling pages (a multi-day trip and highlights). I want to store all the images in the parent’s bundle, and let the file.md access those resources.

slug/
slug/_index.md
slug/highlights.md
slug/day1.md
slug/day2.md
slug/day3.md
slug/image1.jpg
slug/image2.jpg
slug/image3.jpg

slug2/_index.md
slug2/day1/index.md
slug2/day1/image1.jpg
slug2/day1/image2.jpg
slug2/day2/index.md
slug2/day2/image1.jpg
slug2/day2/image2.jpg

In the case of slug1/day1.md, a bundle-less page, to utilize .Parent.Resources but in the case of slug2/day1/index.md which has images in its page bundle, it can just access .Resources.

What’s the Hugo-proper way to say “I have my own page bundle, use that” vs “I am a bundle-less page, so I want to access my .Parent’s page bundle resources.”?

.Page.BundleType

Every Page has a Resources method, but it will be empty for “non bundles” and bundles without any resources.

So doing something ala will work:

{{ $resources := .Resources }}
{{ if not $resources }}
{{ $resources = .Parent.Resources }}
{{ end }}
2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.