Oh, sure!
First, hereβs my content architecture:
.
βββ content
β βββ dental_work
β β βββ pediatrics.md
β β βββ young-adult.md
β β βββ etc-etc.md
β βββ careers
β β βββ cities.md
β β βββ suburban.md
β β βββ etc-etc.md
β βββ mentoring
β β βββ universities.md
β β βββ communities.md
β β βββ etc-etc.md
So, as I wrote earlier, If I am in page pediatrics.md
, I want all the pages in the same section to be listed in a side menu, and the current page to be highlighted with class=active
. .Site.Menu
seems to fit this purpose.
First, each section gets a menu name. So, not just one menu called main
as explained in the Hugo manual. Therefore, in pediatrics.md
, the front matter is:
menu:
dental_work:
parent: "dental_work"
weight: 1
All the content pages in dental_work
must have this front matter. weight
is for the ordinal display in the menu.
Pages in section careers
get this front matter:
menu:
careers:
parent: "careers"
weight: n
Pages in section mentoring
get this front matter:
menu:
mentoring:
parent: "mentoring"
weight: n
In the sidebar navigation template that I made for the page template, I have:
{{ $currentNode := . }}
{{ $thisSection := .Section }}
{{ range (index .Site.Menus $thisSection) }}
{{ if .HasChildren }}
<ul class="nav" id="section-list">
{{ range .Children }}
<li class="{{if $currentNode.IsMenuCurrent $thisSection . }} active{{end}}"><a href="{{.URL}}">{{ .Name }}</a></li>
{{ end }}
</ul>
{{end}}
{{end}}
Thatβs it. Let me know if Iβm missing anything.
-Z