I don’t get my menu design to work. The menu is ok, but marking the currently active item is a bit hard.
I have the following structure in my content:
content/
content/page/*
content/post/
content/post/2019/01
content/post/2019/02
...
content/sitewide/*
content/tags/*
Simply said I would like to mark a menu item active if it’s the current page (inside of the page folder) or if the menu item is the archive (either list pages for posts, taxonomies or single items) or we see a post (one of the items inside of content/post).
I would have expected the following piece to work:
{{ $currentPage := . }}
{{ range .Site.Menus.main }}
<li class="nav-item{{if or ($currentPage.IsMenuCurrent "main" .) ($currentPage.HasMenuCurrent "main" .) (and (eq $currentPage.Type "post") (eq .Identifier "archiv" )) }} active{{end}}">
<a href="{{.URL}}"{{if eq .Page nil }} target="_blank" rel="noopener noreferrer"{{ end }} class="nav-link">
<span class="icon larger light" aria-hidden="true">
{{ partialCached (print .Pre) .}}
</span>
{{ .Name }}
</a>
</li>
{{ end }}
It doesn’t though. The archive link is ALWAYS marked active. (The menu entry is in page frontmatter and it’s identifier is “archiv” - German ;] ).
What would be the correct way to use a whole section as an indicator? I tried .Section
, but that makes ALL links in the nav active.
The front matter in the page-folder explicitly marks them as type: page
.
The repo is here: https://github.com/davidsneighbour/samui-samui.de