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:

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

For the sub-menu I used this code:

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

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