I try to move towards the built-in menu system for most of my navigation - using IsMenuCurrent and HasMenuCurrent for the “active” stuff.
IsMenuCurrent works fine in both cases (NOTE: this is in 0.13-DEV, these method weren’t implemented on Node in 0.12), and I wrote this “hack” to add support for HasMenuCurrent for sections, without having to add menu config to every page, see https://github.com/spf13/hugo/pull/779
I basically want “one loop” / one way to handle my menu builds, not a lot of if/else hacks.
Yeah i tried to use the built in menu stuff, but i still have the same fundamental problem: ‘active’ states work for archetypes but not static sections. Maybe i’m missing something:
I’m new to Hugo and I’m currently building my small company website. I have the exact problem as described here by Brad and I’d like very much to share fix you mentioned with us.
I also have main menu (named portal) defined in config, consisting of mostly static pages without archetype. For those pages I can not get highlighted menu. My code is here:
{{ range .Site.Menus.portal }}
<li><a href="{{ .Url }}" {{ if $currentNode.IsMenuCurrent "portal" . }}class="active-page"{{ end }}>{{ .Name }}</a></li>
{{ end }}
Highlight gets properly displayed only for blog, which also does not have any special archetype (for now), but it’s root page ( / ).
Hi, I am a new Hugo user, and I have the same problem. The home page and blog page get highlighted but a static page doesn’t get highlighted. Help appreciates
Aha! Thank you. That was my missing piece. To be a bit more verbose:
site config.toml - removed the reference to static page completely
Then, in the front matter of the static page itself I added
menu = “main”
Had the same problem - the “active” flag (IsMenuCurrent or HasMenuCurrent) was not working for nodes when declared in config.toml.
The solution was to declare it in front matter, which is unfortunate since it would be preferable to keep all menu items together.
To set the weight and other properties - and this is not explained in the docs - use the following formatting:
+++
[menu]
[menu.main]
name = "About me"
weight = -30000
+++