How to iterate over nested branch .Pages from parent page

I’m trying to make a category pages that list only it’s direct descendants. If that page doesn’t have an image specified for its thumbnail in the front matter, I’ve written a template to recursively search all of its subpages for the first page that has an image. The problem that’s preventing me from doing this is that the children’s .RegularPagesRecursive (or even .Pages) isn’t defined when iterating over .Pages from the parent page.

For example, I would have in my list.html the following

{{ range .Pages }} <!-- Iterate over current branch's direct descendants -->
  {{ $subthumb := "" }}
  {{ with .Params.thumb }} <!-- Check if descendant has a picture in mind for a thumbnail -->
    {{ $subthumb = . }}
  {{ else }} <!-- Otherwise find the first subpage that has an image -->
    {{ $subthumb = partial "utils/img/thumb/recurse.html" .RegularPagesRecursive }}
  {{ end }}
{{ end }}

But this doesn’t work because .RegularPagesRecursive for the subpage doesn’t seemed to be defined here.

It is defined. Try it:

git clone --single-branch -b hugo-forum-topic-35661 hugo-forum-topic-35661
cd hugo-forum-topic-35661
hugo server

But remember that .RegularPagesRecursive does not include list pages.

Hmm… I haven’t looked at your code yet but I’ll try to extract the relevant code from my project into a working example to show here to see what’s going wrong. Can’t do it tonight so I’ll try to get in a few days

After isolating the relevant code I think issue I was having may had to do with having folders in which I hadn’t added an files to yet under some branch bundles. I was able to get the recursive image search working correctly (just need to test a few things to make sure it’s working exactly as I intended), however I’m noticing another strange behavior that I can’t seem to resolve that I’ll open a seperate issue for.

Here’s a link to the new issue I made:

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