I have information pages on my site, which are grouped by service. Let’s say I have service A and B, with matching menus. Pages about service A have the servicea menu specified, and those about service B have the menu serviceb.
I’d like to display a sidebar menu conditionally. If the current page has menu “servicea” set in its frontmatter, then I’d like to show the corresponding menu, and vice versa for “serviceb”. Conversely, I don’t want to show both menus.
The following works to show the “servicea” menu, but, it appears for all inner pages pages, including those pages with only “serviceb” set.
{{- $currentPage := . -}}
{{ range .Site.Menus.servicea }}
<a href="{{ .URL | absLangURL }}"><p class="menu-label">{{ .Name }}</p></a>
<ul class="menu-list">
{{ if .HasChildren }}
{{ range .Children }}
<li><a class="is-hoverable{{ if $currentPage.IsMenuCurrent "servicea" . }} is-active{{ end }}" href="{{ .URL | absLangURL }}">{{ .Name }}</a></li>
{{ end }}
{{ end }}
{{ end }}
</ul>
I can see that {{ $currentPage.Menus }} is a map but, I cannot use “in” on it.
Can anyone tell me, how can I test which menu the current page has, then show the appropriate menu for it?
{{ with .Params.menu }}
{{- $currentPage := . -}}
{{ range .Site.Menus.outsourcing }}
...
{{ end }}
Neither with .Params.menu nor with .Params.menu.outsourcing returns anything.
When I tried making it exactly like what you said, first I got an error about the =, so I tried changing to :=. Then it complained about the index, so, I started looking into what is being seen, step by step.
Hi @regis, it’s very much a messy “work in progress” so it’s embarrassing to share, but, thank you! The repo is here:
I guess the relevant bits are as follows. I’m starting hugo server like this:
hugo server --navigateToChanged --buildDrafts --watch --verbose --source="/path/to/eSolia_2018" --config="/path/to/eSolia_2018/config.toml" --port=1366
I’ve been editing the sidebar menu here in the single: