I want to add a custom class
to some menu items and the Hugo documentation shows exactly how to do it. Except I can’t get it to work.
In layouts/partials/header.html
, I added the exact example HTML from the Hugo documentation:
<nav class="sidebar-nav">
{{ range .Site.Menus.main }}
<a href="{{ .URL }}" title="{{ .Title }}" class="{{ with .Params.class }}{{ . }}{{ end }}">
{{- .Name -}}
</a>
{{ end }}
</nav>
The Hugo documentation shows how to add params
for class
in config.toml
:
[menu]
[[menu.main]]
identifier = "about"
name = "about hugo"
pre = "<i class='fa fa-heart'></i>"
url = "/about/"
weight = -110
[menu.main.params]
class = "highlight-menu-item"
However, the above is not multilingual, so I adjusted this for my multilingual config.toml
:
[[Languages.en.menu.main]]
weight = 9
name = "Sign In"
URL = "signin/"
[Languages.en.menu.main.params]
class = "display-signed-out"
That did not work, so I tried a different TOML approach to defining params
:
# My second try, which did not work either
[[Languages.en.menu.main]]
weight = 9
name = "Sign In"
URL = "signin/"
params = { class = "display-signed-out" }
With both of the above versions of config.toml
I get the error,
executing "partials/header.html" at <.Params.class>:
can't evaluate field Params in type *navigation.MenuEntry
Indeed params
is not listed as a Menu Entry Variable in the documentation.