Troy
August 7, 2020, 4:45pm
1
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
Troy
August 7, 2020, 6:31pm
2
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 }}
bep
August 7, 2020, 6:54pm
3
There is also a .RegularPagesRecursive
method as of recently.
1 Like
Troy
August 8, 2020, 12:34pm
4
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
.
system
Closed
August 10, 2020, 12:34pm
5
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.