hugo/docs/content/en/methods/menu-entry/Identifier.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

1.2 KiB

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

The Identifier method returns the identifier property of the menu entry. If you define the menu entry automatically, it returns the page's section.

{{< code-toggle file=hugo >}} menus.main identifier = 'about' name = 'About' pageRef = '/about' weight = 10

menus.main identifier = 'contact' name = 'Contact' pageRef = '/contact' weight = 20 {{< /code-toggle >}}

This example uses the Identifier method when querying the translation table on a multilingual site, falling back the name property if a matching key in the translation table does not exist:

<ul>
  {{ range .Site.Menus.main }}
    <li><a href="{{ .URL }}">{{ or (T .Identifier) .Name }}</a></li>
  {{ end }}
</ul>

{{% note %}} In the menu definition above, note that the identifier property is only required when two or more menu entries have the same name, or when localizing the name using translation tables.

{{% /note %}}