HUGO
News Docs Themes Community GitHub

Parent

Returns the parent property of the given menu entry.

Syntax

MENUENTRY.Parent

Returns

string

With this menu definition:

[menus]
  [[menus.main]]
    name = 'Products'
    pageRef = '/product'
    weight = 10
  [[menus.main]]
    name = 'Product 1'
    pageRef = '/products/product-1'
    parent = 'Products'
    weight = 1
  [[menus.main]]
    name = 'Product 2'
    pageRef = '/products/product-2'
    parent = 'Products'
    weight = 2

This template renders the nested menu, listing the parent property next each of the child entries:

<ul>
  {{ range .Site.Menus.main }}
    <li>
      <a href="{{ .URL }}">{{ .Name }}</a>
      {{ if .HasChildren }}
        <ul>
          {{ range .Children }}
            <li><a href="{{ .URL }}">{{ .Name }}</a> ({{ .Parent }})</li>
          {{ end }}
        </ul>
      {{ end }}
    </li>
  {{ end }}
</ul>