Hey,
I’m new to Hugo.
I’m trying to keep the current page/section highlighted in the top menu.
I’ve tried the solutions suggested
-
and here from stackoverflow :
questions/48589485/highlighting-currentmenuitem-in-a-hugo-menu-that-is-defined-in-config-file
Then in /layouts/partials/menu.html I have tried the solutions suggested in the above links:
<!-- @ian copied this from:-->
<!-- https://stackoverflow.com/questions/48589485/highlighting-currentmenuitem-in-a-hugo-menu-that-is-defined-in-config-file -->
{{ $currentPage := . }}
{{ range .Site.Menus.main }}
{{ $menu_item_url := .URL | relLangURL }}
{{ $page_url:= $currentPage.RelPermalink | relLangURL }}
{{ if eq $menu_item_url $page_url }}
{{/* the menu item links to the current page (with relLangURL) */}}
{{ end }}
{{ end }}
<!-- @ian copied this from:-->
<!-- https://discourse.gohugo.io/t/highlight-current-menu-item-config-toml/22723 -->
{{ $currentPage := . }}
{{ range .Site.Menus.main }}
<li>
<a href="{{ .URL }}"
{{ if or ($currentPage.IsMenuCurrent "main" .) (eq $currentPage.Section .Identifier) }}
class="active"
{{ end }}
{{ .Name }}</a>
</li>
{{ end }}