KeyName
Returns the
identifier property of the given menu entry, falling back to its name property.- Syntax
- MENUENTRY.KeyName
- Returns
- string
In this menu definition, the second entry does not contain an identifier, so the Identifier method returns its name property instead:
menus:
main:
- identifier: about
name: About
pageRef: /about
weight: 10
- name: Contact
pageRef: /contact
weight: 20
[menus]
[[menus.main]]
identifier = 'about'
name = 'About'
pageRef = '/about'
weight = 10
[[menus.main]]
name = 'Contact'
pageRef = '/contact'
weight = 20
{
"menus": {
"main": [
{
"identifier": "about",
"name": "About",
"pageRef": "/about",
"weight": 10
},
{
"name": "Contact",
"pageRef": "/contact",
"weight": 20
}
]
}
}
This example uses the KeyName method when querying the translation table on a multilingual project, 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 (.KeyName | lower)) .Name }}</a></li>
{{ end }}
</ul>In the example above, we need to pass the value returned by .KeyName through the strings.ToLower function because the keys in the translation table are lowercase.
Last updated:
June 18, 2026
:
Merge commit 'c86d9f4aa8a58931f52df6516f10b67c807505fb' (be780afa7)
Improve this page