Adding a child to a menu item

I have a menu and I want to open a new menu at the bottom when it comes to the elements of this menu.

[[menu.main]]
  name = 'Project'
  title = 'Project'
  url = '/project/'
  weight = 20

For example, the code above adds “Project” to the menu, but when I hover over “Project” I will create new elements at the bottom.

How can I do this?

Use the Parent field

For example,

[[menu.main]]
  identifier = 'project'
  name = 'Project'
  title = 'Project'
  url = '/project/'
  weight = 20

[[menu.main]]
  parent = 'project'
  name = 'Foo'
  title = 'Foo'
  url = '/foo/'
  weight = 30

Then in your header or menu template

{{ range .Site.Menus.main }}
  {{ if .HasChildren }}
    <!-- Menu entry has children, iterate through them -->
      {{ range .Children }}
        <a href="{{ .URL }}">{{ .Name }}</a>
      {{ end }}
  {{ else }}
   <a href="{{ .URL }}">{{ .Name }}</a>
  {{ end }}
{{ end }}
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.