I’ve been using Hugo for a few years, building several sites already. I’m currently rebuilding an old site in Hugo witch has a deep folder structure. As part of the template, I want to have a nav block that lists the other regular pages in the same folder in the single template. It seems like this should be possible but I haven’t figured out the code from the docs and I’m not finding any examples. I think the following code should be close but doesn’t produce any links:
{{ with .File }}
{{ $pages := where site.RegularPages "Dir" .Dir }}
{{ range $pages }}
<p><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></p>
{{ end }}
{{ end }}
{{ range .Parent.RegularPages }}
{{ if ne $ . }}<!-- skip current page -->
<p><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></p>
{{ end }}
{{ end }}
{{ with .File }}
{{ $section := site.GetPage .Dir }}
{{ range $section.RegularPages }}
<p><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></p>
{{ end }}
{{ end }}
@irkode example works perfectly when dealing with Hugo sections.
But only the first level of directories inside the content directory are proper Hugo sections. All the sub directories are just that, from Hugos point of view.
the .File version would need an index.md cause we need a File.
If there’s none (if that is possible) using Page.Path | path.Dir to get the parent page may be an option… just thought out loud
the .Parent will need at least an empty --- --- _index.md in each folder
you may even suppress the rendering of the list pages using build options but than ofc you will have to generate links to the pages somewhere else