Navigation: Problem with top-menu and sub-menu

Hello, thanks for HUGO and thanks for this forum…

I try to build a navigation.

Top-Menu: should show all section on Level 1 (root sections)

Sub-Menu: should show the contents of the active root section, e.g. pages and subsections (but not the pages and the subsubsections in this subsection)

For the top-menu I used this code:

<ul>
  {{ range .Site.Menus.main }}
    <li>
        <a href="{{ .URL }}">
          {{ .Name }}
        </a>
    </li>
  {{ end }}
</ul>

For the sub-menu I used this code:

<ul>
  {{ $a := .Section }}
  {{ range where .Site.Pages ".Section" $a }}
    <a href="{{ .URL }}"><li>{{ .Title}}</li></a>
  {{ end }}
</ul> 

Problem: The sub-menu does not show only Pages and subsections of the active root section. It shows also the content (pages and subsubsections) of the subsections.

Can anybody show me the way to achieve the wanted behaviour of the navigation?

Thank you very much for helping, rufus42

1 Like