Hey All,
I have read through a bunch of the posts and comments here and so far I am having no joy with highlighting the current menu item. Here is the menu portion of my config.toml
[menu]
[[menu.main]]
identifier = "homepage"
name = "Home"
url = "/"
weight = 1
[[menu.main]]
identifier = "about"
name = "About"
url = "/about"
weight = 2
[[menu.main]]
identifier = "experiments"
name = "Experiments"
url = "/experiments"
weight = 3
[[menu.main]]
identifier = "partnership"
name = "Partnership"
url = "/partnership"
weight = 4
[[menu.main]]
identifier = "accelerator"
name = "Accelerator"
url = "/accelerator"
weight = 5
In my template I have the following:
{{ $currentPage := . }}
{{ range .Site.Menus.main }}
<li>
<a href="{{ .URL }}" {{ if $currentPage.IsMenuCurrent "main" . }}class="active"
{{ end }}>{{ .Name }}</a>
</li>
{{ end }}
I have also tried the above with:
{{ if or ($currentPage.IsMenuCurrent "main" .) ($currentPage.HasMenuCurrent "main" .) }}class="active"{{ end }}
My content directory has the following structure:
content
> about
> _index.md
...
_index.md
When I load up the homepage, the menu item is highlighted and everything is great. When I navigate to any other page however, the relevant menu item is no longer being highlighted i.e. class is not being added.
When I had the menu items configured inside each content .md file all worked well but, I ran into a problem where the CMS would overwrite the contents of these files and remove the menu configuration so, I am looking at configuring the menu from config.toml
Another aspect of this that might, or might not affect the end result is that, except for the homepage the other pages have a custom layout and type, for example:
type: "accelerator"
layout: "accelerator"
Anyone else run into this problem and was able to solve it? Thank you all.