Iterate over sibling pages in child section

Directory structure:


In the layout that applies to, I would like to iterate over all of its sibling pages, i.e. b1 and c1 and only those. It can return a1, too.

I tried:

{{ range .Page.Parent.Pages }}

but that .Page.Parent seems to refer to the systems section, and gives me far too much. How do I do this?

content/systems/sys1/ is not a Section. So the Parent of a1 is /systems/.

I would suggest a restructure:

β”œβ”€β”€ sys1
β”‚   β”œβ”€β”€   #
β”‚   β”œβ”€β”€
β”‚   └──
└── sys2
    β”œβ”€β”€   #

I could do that if there is no other way, but I’d rather not as the URL namespace is important to me.

If by URL you mean the rendered paths, I’m not sure I understand: systems/sys1/ and systems/ will both be rendered to (assuming default configs elsewhere) so that URL will not change.

If you really do not want to do that, you could perhaps play around with some .File.Path filtering.

This is possible with the .CurrentSection variable, which would give access for to all pages in /systems/sys1/. There’s more information here: section page variables and methods.

This does require that you use files. Even though you don’t, Hugo requires them. I don’t know of an option to work around that.

Ha! It’s working. I hadn’t understood that defines a section, apparently, and that .CurrentSection.Pages contains the pages of the current section. Thanks, everybody.

1 Like