Iterate over all menus - best way?

It is possible to define several menus in the config.yaml, then iterate over all of them with:

{{ range. Site.Menus }}

What I want to do next is something like:

<h3>{{ .Name }}</h3>

Where name is the name of the menu.

But it looks like this isn’t possible? Do I have to group all menus under one main menu, in order to iterate like this?


You can try something like:

{{ range $key, $menu := .Site.Menus }}
  <h2>{{$key}}</h2> <!-- Menu name -->

  {{ range $menu }} <!-- Menu items -->
    {{.Name}} - {{.URL}}
  {{ end }}

{{ end }}

1 Like