The above does not seem right. What type of .Resources are you trying to range through? You need to use a method to return the given resources by type. See: Page resources | Hugo
Also everything in Hugo is a .Page including Section list pages.
If this does not clear things up, you need to show us more from your project like its content structure. So a link to your repository would help.
.Resources is just a slice of resources. The (Get)Match methods are just to filter that slice. So if you donāt specify a resource filtering method, you get all the available resources.
Now, thereās a qualified yes thereā¦ itās available only for non-page resources. I.e. you donāt have Permalink only for page resources in leaf bundles.
Each section is a Page too. Broadly speaking, Hugo has 2 kinds of pagesā¦ pages that show the post content (like regular pages showing single blog posts), and list pages (like home page, section page, taxonomy pages, etc.). The list pages are typically used to link the regular/single pages. But with branch bundle _index.md files, you can also specify content and front-matter for such list pages.
I maintain a theme called hugo-bare-min-theme with ample debug info to help understand such Hugo internals. Hereās the single.html template from there, that uses the .Resources (an example page using that layout).
I think we need more examples with range and .Resources in the Docs. Like updating and moving the examples from the old (and currently outdated) Hugo 0.32 HOWTO
It would be better to have everything in one place (so that people like me donāt forget the basic stuff).
Iām a bit busy with the GDPR stuff and Hugoās internal shortcodes right now and I donāt have the time to contribute to the Docs currently, but if you donāt have the time for this Iāll do it once I can.
To be specific (as this thread needs more chefs ā¦): The **method is there ** on the Resource interface, but Permalink will return a blank string for the pages inside the bundles (that never gets written to disk and donāt have an URL).
executing "main" at <.Resources.GetByPref...>: can't evaluate field Resources in type *hugolib.Page
That is why I tried to understand my mistake by looping through all sections expecting them to contain at least an empty array of resources, but apartenly I understood something wrong there.
can't evaluate field Resources in type *hugolib.Page
This error comes from the Golang template framework. *hugolib.Page has a Resources field, but since it is nil in this case, you get a slightly confusing error. I remember vaguely that methods behaves different from fields in this situation, so maybe we could make it into a method. It is perfectly fine to call methods on nil types.
Thank you for being so responsive. Yes, I guess an empty array would be more expected in that case.
As for my specific problem, I did not share a ādemoā repository because the I cannot reproduce it outside of my project.
I think this means I have to investigate why the resources are empty on this specific section while there are image files co-located with the _index.md file as shown above. Just having image files in the same folder should be enough, right?
I think something ala cannot ... on nil *hugolib.Page would be better, because that is the source of the problem. An empty array/slice would indicate something different.