List all pages below subsection

I have a website with multiple sections and subsections.

Example: In the first section there are four subsections.

/section-1/subsection-1
/section-1/subsection-2
/section-1/subsection-3
/section-1/subsection-4

In each subsection there are more nested sections (folders with _index.html).

Example: In the first subsection there are six subpages.

/section-1/subsection-1/subsubsection-1
/section-1/subsection-1/subsubsection-1/example-1
/section-1/subsection-1/subsubsection-1/example-2
/section-1/subsection-1/subsubsection-2
/section-1/subsection-1/subsubsection-3
/section-1/subsection-1/subsubsection-4

On /section-1/subsection-1/subsubsection-1 I want to list all pages which are below this path.

I know how to list all pages below section 1…

{{ range where .Site.Pages "Section" "section-1" }}

{{ end }}

…but not those below /section-1/subsection-1/subsubsection-1.

1 Like

Based on this GitHub comment I found a very easy solution:

list.html

  {{ range .Sections }}
    <li>
        <a href="{{.Permalink}}">{{.Title}}</a>
    </li>
      {{ partial "lists/recursive.html" . }}
  {{ end }}

partials/lists/recursive.html

{{ $child_pages := union .Sections .Pages }}
{{ range $child_pages }}
  <li><a href="{{.Permalink}}">{{.Title}}</a></li>
  {{ partial "lists/recursive.html" . }}
{{ end }}

There is also a .RegularPagesRecursive method as of recently.

1 Like

I really like the idea behind the new method, but in my case ALL pages are sections (to make the section tree fully navigational). So it would be nice to have something like .SectionsRecursive.

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