How to build one collection for all nested sections?

The recursive “function”:

{{ define "subpages" }}
  {{ if .Pages }}
    {{ range .Pages}}
      {{ if eq .Kind "section" }}<a href="{{ .Permalink }}">{{ .Title }}</a><br>{{ end }}
      {{ template "subpages" . }}
    {{ end }}
  {{ end }}
{{ end }}

All pages from root sections:

{{ range .Site.Sections }}
  <a href="{{ .Permalink }}">{{ .Title }}</a><br>
  {{ template "subpages" . }}
{{ end }}

So you can choose the sort method you want (date, weight, etc.) in the range loops (for .Site.Sections and .Pages in subsections).

1 Like