Hi,
I got following structure of menu
<nav>
<div class="menu-header">Main Menu</div>
<div class="menu-container">
<ul class="main-menu">
{{ $currentPage := . }}
{{ range .Site.Menus.side }}
{{ if .HasChildren }}
{{ $submenuActive := false }}
{{ range .Children }}
{{ if eq $currentPage.RelPermalink .URL }}
{{ $submenuActive = true }}
{{ end }}
{{ end }}
<li class="menu-item expandable{{ if (eq $currentPage.RelPermalink .URL) }} active{{ end }}{{ if $submenuActive }} submenu-active{{ end }}"><a href="{{ .URL | absURL }}">{{ .Name }}</a></li>
<ul class="sub-menu{{ if $submenuActive }} submenu-open{{ end }}">
{{ range .Children }}
<li class="sub-menu-item{{ if (eq $currentPage.RelPermalink .URL) }} active{{ end }}"><a href="{{ .URL | absURL }}">{{ .Name }}</a></li>
{{ end }}
</ul>
{{ else }}
<li class="menu-item{{ if (eq $currentPage.RelPermalink .URL) }} active{{ end }}"><a href="{{ .URL | absURL }}">{{ .Name }}</a></li>
{{ end }}
{{ end }}
</ul>
</div>
</nav>
Which works in a way, that if I am on an expandable menu, top-level, sub-menu is open. When on sub-menu, the current top menu and submenu is open (active).
I am trying to work out with .IsMenuCurrent .HasMenuCurrent as wells as with .IsAncestor or .InSection to get menu and submenu open when I am on page that going into 3rd level
1st: /expandable-menu/ (Page 1)
2nd: /expandable-menu/sub-menu-in-expandable/ (Page 2)
3rd: /expandable-menu/sub-menu-in-expandable/page-3
When I am on page 3, the expandable menu, as well as sub-menu, is no longer active.
Any help will be appreciated.
found this post and using that
{{ $active := or ($currentPage.IsMenuCurrent "side" .) ($currentPage.HasMenuCurrent "side" .) }}
{{ $active = or $active (eq .Name $currentPage.Title) }}
{{ $active = or $active (and (eq (trim (path.Dir .URL) "/") $currentPage.Section) (ne $currentPage.Section "")) }}
{{ if $active }} i-am-in-this-part-of-menu {{ else }} not {{ end }}
and is working if 3rd level pages if subfolder match menu hierarchy.
This sort the problem.