I currently have 2 menus in my config.toml file and I would like to be able to choose which menu to use in the front matter. This may be super trivial, but I couldnt find an answer when searching for it.
Here’s what I have so far, which kinda works, but I get a weird artifact issue.
config.toml
[[menu.main]]
name = "Features"
pre = "<i class='fas fa-heart'></i>"
weight = -110
identifier = "about"
url = "/about/"
[[menu.main]]
name = "Sections"
pre = "<i class='fas fa-heart'></i>"
weight = -110
identifier = "child"
url = "/style-guide/"
parent = "about"
[[menu.main]]
name = "getting started"
pre = "<i class='fas fa-road'></i>"
weight = -100
url = "/style-guide/"
[[menu.test]]
name = "Pricing"
pre = "<i class='fas fa-heart'></i>"
weight = -110
identifier = "about"
url = "/about/"
[[menu.test]]
name = "Sections"
pre = "<i class='fas fa-heart'></i>"
weight = -110
identifier = "child"
url = "/style-guide/"
parent = "about"
[[menu.test]]
name = "getting started"
pre = "<i class='fas fa-road'></i>"
weight = -100
url = "/style-guide/"
_index.md file
EDIT
---
page_title: Docs
nav-menu: test
---
Original - using menu
parameter for menu switching was causing the error.
---
page_title: Docs
menu: test
---
Nav.html
<ul class="navbar-nav">
{{ $currentPage := . }}
{{ $menu := index .Site.Menus .Params.nav-menu }}
{{ range $menu }}
{{ if .HasChildren }}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{.Name}}
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
{{ range .Children }}
<a class="dropdown-item {{if or ($currentPage.IsMenuCurrent "main" .) ($currentPage.HasMenuCurrent "main" .) }}active{{ end }}" href="{{ .URL }}">{{ .Name }}</a>
{{end}}
</div>
</li>
{{ else }}
<li class="nav-item {{if or ($currentPage.IsMenuCurrent "main" .) ($currentPage.HasMenuCurrent "main" .) }}active{{ end }}">
<a class="nav-link" href="{{.URL}}">{{.Name}} {{ if $currentPage.HasMenuCurrent "main" . }}<span class="sr-only">(current)</span>{{ end }}</a>
</li>
{{ end }}
{{ end }}
</ul>
This method allows for menu switching from the front matter, however, I get a weird additional empty menu option as an artifact, which I’m guessing is because hugo is trying to make a menu option from the front matter’s menu declaration of menu=test and the use of the index function.
<li class="nav-item active">
<a class="nav-link" href="/style-guide/"> <div class="ripple-container"></div></a>
</li>
Any suggestions how I can make this more clean?
EDIT: Got it to work the way I wanted it to - see below comment. Still open on ways to clean it up / better process. Also active
still doesnt work the way it should.