Can't evaluate field Params in type *navigation.MenuEntry

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.

What Hugo version are you using?

hugo version

Edited to add:

The Menu Params feature was added only recently, as of 0.79. If you are using an older version then you would get an error.

1 Like

Forgive me. I forgot the one thing that must be in every such question. It’s Hugo Static Site Generator v0.74.3-DA0437B4/extended linux/amd64 BuildDate: 2020-07-23T16:30:30Z.

Upgrading to version 0.79 fixes the problem.

2 Likes

It’s a new feature in 0.79.0 :wink:

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.