Skip to content

Instantly share code, notes, and snippets.

@jbfriedrich
Created January 5, 2022 05:16
Show Gist options
  • Save jbfriedrich/2fce7de5c55ef781d405a92da8c55ee9 to your computer and use it in GitHub Desktop.
Save jbfriedrich/2fce7de5c55ef781d405a92da8c55ee9 to your computer and use it in GitHub Desktop.
Hugo Template - List All Menu Entries
<!-- Loop through the navigation items -->
{{ $currentPage := . }}
{{ $menuitems := (.Site.Menus.main) }}
{{ $len := (len $menuitems) }}
{{ range $index, $element := $menuitems }}
{{ $id := .Identifier }}
<li class="header-nav-item">
<a class="header-nav-entry{{if or ($currentPage.IsMenuCurrent "main" .) ($currentPage.HasMenuCurrent "main" .) }} active{{end}}" title="{{ .Name }}" href="{{ .URL }}">
<span class="header-nav-entry-icon">{{ .Pre }}</span>
<span class="header-nav-entry-text">{{ .Name }}</span>
</a>{{ if ne (add $index 1) $len }} • {{ end }}
</li>
{{ end }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment