mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-28 22:19:59 +02:00
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
``` git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash ``` Closes #11925
This commit is contained in:
39
docs/content/en/methods/menu-entry/KeyName.md
Normal file
39
docs/content/en/methods/menu-entry/KeyName.md
Normal file
@@ -0,0 +1,39 @@
|
||||
---
|
||||
title: KeyName
|
||||
description: Returns the `identifier` property of the given menu entry, falling back to its `name` property.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related: []
|
||||
returnType: string
|
||||
signatures: [MENUENTRY.KeyName]
|
||||
---
|
||||
|
||||
In this menu definition, the second entry does not contain an `identifier`, so the `Identifier` method returns its `name` property instead:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menus.main]]
|
||||
identifier = 'about'
|
||||
name = 'About'
|
||||
pageRef = '/about'
|
||||
weight = 10
|
||||
|
||||
[[menus.main]]
|
||||
name = 'Contact'
|
||||
pageRef = '/contact'
|
||||
weight = 20
|
||||
{{< /code-toggle >}}
|
||||
|
||||
This example uses the `KeyName` 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 (.KeyName | lower)) .Name }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
|
||||
In the example above, we need to pass the value returned by `.KeyName` through the [`lower`] function because the keys in the translation table are lowercase.
|
||||
|
||||
[`lower`]: functions/strings/tolower
|
Reference in New Issue
Block a user