0.55 broke my menu

I am using a pretty bare-bones menu on my site, and upgrading to 0.55 broke some aspects of it. I’ll attempt to explain it as best I can here.

First my navigation.html partial:

<ul class="sdsw-navigation__list">
        {{ $currentNode := . }}
        {{ range .Site.Menus.main }}
        {{ if .HasChildren }}
            class="sdsw-navigation__item sdsw-navigation__type{{ with .Page.Params.newsection }} new{{ end }} has-submenu{{if or ($currentNode.IsMenuCurrent "main" .) ($currentNode.HasMenuCurrent "main" .) ($currentNode.HasMenuCurrent "resources" .) ($currentNode.IsMenuCurrent "resources" .) }} open{{end}}">
            <a href id="{{ lower .Name }}" aria-haspopup="true" aria-expanded="false">
                {{ .Name | markdownify | title  }}
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16">
                    <use xlink:href="#chevron" />
            <ul class="sdsw-navigation__sublist">
                {{ range .Children }}
                <li class="{{if or ($currentNode.IsMenuCurrent "main" .) ($currentNode.HasMenuCurrent "main" .) }}active{{ end }}{{ with .Page.Params.newpage }} new{{ end }}"
                    {{if or ($currentNode.IsMenuCurrent "main" .) ($currentNode.HasMenuCurrent "main" .) }} id="isCurrent" {{end}}>
                    <a href="{{ .URL }}">{{ .Name | markdownify | title }} </a>
                {{ end }}
        {{ else }}
        <li class="sdsw-navigation__item">
            <a href="{{ .URL }}">{{ .Name | markdownify }} </a>
        {{ end }}
        {{ end }}

Here are the problems I’m encountering:

  • First, the above throws an error for all instances of single.html that says execute of template failed: template: partials/navigation.html:24:77: executing "partials/navigation.html" at <.Params.newsection>: can't evaluate field Params in type *navigation.MenuEntry
  • Changing .Page.Params.newsection to $.Page.Params.newsection and .Page.Params.newpage to $.Page.Params.newpage lets the build go through with no errors. Is that what I should be doing?
  • Even though the site builds correctly, frontmatter weight: values are being ignored, and the pages are being listed alphabetically. This is changed since 0.55.
  • A content markdown file that lives directly under content/ that contains menu:main in its frontmatter is not being displayed at all in the menu. Again, this worked in 0.54.

I’m assuming .Page is the culprit here since that looks to have been altered a bit in 0.55. Otherwise, everything else I’ve checked has matched the docs.

Any ideas here?


Edit: Removed original reply. See below to more info.

Thanks @zwbetz, removing the initial .Page and just using $.Params.newsection.

Bullets 1 & 2 solved of 4 :slight_smile:

Still not sure why weight is being ignored and the one content page is being ignored as well.

1 Like

Hmm, I take it back (a little). While the site is building fine, {{ with $.Params.newsection }} is not finding that parameter that is set on certain pages (ie. newsection: true in the content frontmatter).

Does {{ .Params.newsection }} work?

No, that gives me this error:

execute of template failed: template: partials/navigation.html:24:77: executing "partials/navigation.html" at <.Params.newsection>: can't evaluate field Params in type *navigation.MenuEntry

Hmm. I was wrong then. Going off that error, what I thought was a .Page context is actually a .MenuEntry context. So I’d go with your original workaround

1 Like

So with $.Page.Params.newsection is not being ignored by Hugo, Hugo is just skipping it because the variable is “absent”.

So what changed to where I can no longer access menu item parameters?

The saga continues…

(aka, I just learn how menus work more by reading the docs…)

I’ve used the following to get page parameter access:

{{ with .Page }}
{{ with .Params.newsection }} newsection
{{ end }}
{{ end }}

So now I’m able to successfully access individual menu item page parameters successfully.

Still trying to figure out why weight is broken, and hammering on that. And why a page in the root content folder is being ignored.

0.55.1 fixed these issues.

1 Like