i v read a lot of forums topics on this, but still cant figure this one out.
so i simply want to add and an “active” class to a nav bar menu if i m on the corresponding page.
i ended up using this code:
<ul class="menu__list">
{{- if .Site.Menus.main }}
{{- $currentNode := . }}
{{- range .Site.Menus.main }}
{{- if .Name }}
<li class="menu__item {{ if or ($currentNode.IsMenuCurrent "main" .) ($currentNode.HasMenuCurrent "main" .) }}active{{ end }}">
<a class="menu__link" href="{{ .URL }}">
<span class="menu__text">{{.Name }}</span>
</a>
{{- end }}
{{- end }}
</li>
</ul>
{{- end }}
here is a part of my config file:
[languages.en.menu]
[[languages.en.menu.main]]
identifier = "home"
name = "Home page"
url = "/"
pageRef= "/"
weight = 1
[[languages.en.menu.main]]
identifier = "connect"
name = "How to connect"
url = "/how-to-connect"
pageRef= "how-to-connect"
weight = 2
[[languages.en.menu.main]]
identifier = "reg"
name = "Create account"
pageRef= "create-account"
url = "/create-account"
weight = 3
my main concern is that it works just fine when i run it locally, i get the “active” class on all the menus.
however, when i push it to the web hosting, i only get the “active” class on my home page.
i v read this to find out about the refPage so i added it
i also saw this this so i tried to remove the “url”, it didnt work out
thanks in advance for any help