I am using .IsMenuCurrent
to set an is-active
flag for my navbar links. Here is a minimal version of my navbar (assuming no children):
<nav class="navbar" role="navigation">
<div class="navbar-end">
{{ $currentPage := . }}
{{ range .Site.Menus.main }}
<a class="navbar-item{{ if $currentPage.IsMenuCurrent "main" . }} is-active{{ end }}" href="{{ .URL | relURL }}">
{{ .Name }}
</a>
{{ end }}
</div>
</nav>
And here is the relevant part of my config file:
[menu]
[[menu.main]]
name = "Home"
url = "/"
weight = 1
[[menu.main]]
name = "Posts"
url = "/posts/"
weight = 2
[[menu.main]]
name = "Projects"
url = "/projects/"
weight = 3
[[menu.main]]
name = "Teaching"
url = "/teaching/"
weight = 4
[[menu.main]]
name = "People"
url = "/people/"
weight = 5
For reference, I have an _index.html
template for “Home”, “Posts” and “Projects” are sections that use a _default/list.html
template, and “Teaching” and “People” are single pages that use a _default/single.html
. When I am on the “Home”, “Posts”, or “Projects” page, {{ if $currentPage.IsMenuCurrent "main" . }}
returns true
and the appropriate navbar link is active. However, when I am on the “Teaching” or “People” page, {{ if $currentPage.IsMenuCurrent "main" . }}
returns false
and the navbar links are inactive. This is unexpected behavior, but I’m having a hard time figuring out where I’m going wrong. The only difference between these pages is that they use the _default/single.html
template.
Any thoughts would be greatly appreciated. Thanks!