Skip to content

Instantly share code, notes, and snippets.

@myobie
Last active August 30, 2020 15:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myobie/00c1c51b18dde80b078e93ff06be17ed to your computer and use it in GitHub Desktop.
Save myobie/00c1c51b18dde80b078e93ff06be17ed to your computer and use it in GitHub Desktop.
Recursively list out sections and pages for a nice hugo navigation for a section or site
{{ define "main" }}
<div id="wrapper">
<div id="sidebar">
{{ partial "sidebar-sections-list.html" .Site.Sections }}
</div>
<div id="content">
<!-- ... -->
</div>
</div>
{{end}}
{{ if gt (len .) 0 }}
<ol class="list list-section">
{{ range sort $section_pages "File.Path" }}
<li class="list-section-page">
<a href="{{ .Permalink }}">{{ .Title }}</a>
{{ partial "sidebar-sections-list.html" (union .Pages .Sections) }}
</li>
{{ end }}
</ol>
{{ end }}
@johnelliott
Copy link

I did not know about len ., thanks. I was able to solve a totally different problem by trying out your code and using that 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment