hugo/docs/content/en/methods/menu-entry/Parent.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

977 B

title description categories keywords action
Parent Returns the `parent` property of the given menu entry.
related returnType signatures
string
MENUENTRY.Parent

With this menu definition:

{{< code-toggle file=hugo >}} 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 {{< /code-toggle >}}

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>