Skip to content

Instantly share code, notes, and snippets.

@celestehorgan
Last active January 29, 2020 11:27
Show Gist options
  • Save celestehorgan/41f09b89aacfed430c095f194c5df58d to your computer and use it in GitHub Desktop.
Save celestehorgan/41f09b89aacfed430c095f194c5df58d to your computer and use it in GitHub Desktop.
Hugo - Iterate over section and subsections
{{ $allSections := site.Sections }} <!-- "blog" and "docs" -->
{{ $docsSections := where $allSections "Section" "docs" }} <!-- "getting-started" and "deployment" -->
{{ $thisUrl := .RelPermalink }} <!-- the URL of the current page -->
<h2>Docs</h2>
{{ range $docsSections }}
<ul>
<li>
{{ .Title }}
{{ range .RegularPages }}
<ul>
<li>
{{ .Title }}
</li>
</ul>
{{ end }}
</li>
{{ range .Sections }}
<li> {{ .CurrentSection.Title }}
<ul>
{{ range .CurrentSection.RegularPages }}
<li>
{{ .Page.Title }}
</li>
{{ end }}
</ul>
</li>
{{ end }}
</ul>
{{ end }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment