Hi,
Given the following content folder structure:
.
├── content
│ ├── section1
│ │ ├── overview1.md
│ │ ├── about1.md
│ │ ├── contact1.md
│ ├── section2
│ │ ├── overview2.md
│ ├── section3
│ │ ├── overview3.md
what I’m trying to achieve is that when I navigate to /section1/overview1
for example, a side menu will display all the pages of that section, so overview1
, about1
and contact1
in this case.
In my config.toml
file I have configured a multi menu menu = ["section1", "section2", "section3"]
and each content .md
file has the menu configuration in its metadata. So for example, overview1.md
has the following front matter:
menu:
section1:
identifier: overview1
weight: 1
My sidebar template looks something like this:
{{ $crrPage := . }}
{{ $crrSection := .Section }}
{{ range (index .Site.Menus $crrSection) }}
{{ if .HasChildren }}
<ul class="nav" id="section-list">
{{ range .Children }}
<li class="{{if $crrPage.IsMenuCurrent $crrSection . }} active{{end}}"><a href="{{.URL}}">{{ .Name }}</a></li>
{{ end }}
</ul>
{{end}}
{{end}}
I would aspect this to work, but I am new to Hugo so maybe I’m overlooking something or perhaps it’s more of a conceptual error.
The error I get says: ....at <$crrSection>: range can't iterate over <nil>
{{ range (index .Site.Menus "section1") }}
or {{ range .Site.Menus.section1 }}
work as expected, but anything else I have tried fails with the same error
I’ve looked long and hard everywhere. I found this post which basically describes the same use case, the same solution, which in their case works as expected: [SOLVED - solution posted] How do I put .Site.Menu specific to a section in page template
I’m currently on version v0.54.0
.
If anyone can point me in the right direction I would much appreciate it. I’ve been stuck with this for a while now and it’s very frustrating.
Thank you <3