aboutsummaryrefslogtreecommitdiffhomepage
path: root/docs/content/en/methods/menu-entry/Identifier.md
blob: ba8b77eceb8319d90aab676a7d719e822aa5e558 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
---
title: Identifier
description: Returns the `identifier` property of the given menu entry. 
categories: []
keywords: []
action:
  related: []
  returnType: string
  signatures: [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.

[automatically]: /content-management/menus/#define-automatically

{{< 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:

```go-html-template
<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.

[details]: /content-management/menus/#properties-front-matter
{{% /note %}}