标识符
Syntax
MENUENTRY.Identifier
Returns
string
Identifier
方法返回菜单项的 identifier
属性。如果您 自动 定义菜单项,则它返回页面的章节。
hugo.
menus:
main:
- identifier: about
name: About
pageRef: /about
weight: 10
- identifier: contact
name: Contact
pageRef: /contact
weight: 20
[menus]
[[menus.main]]
identifier = 'about'
name = 'About'
pageRef = '/about'
weight = 10
[[menus.main]]
identifier = 'contact'
name = 'Contact'
pageRef = '/contact'
weight = 20
{
"menus": {
"main": [
{
"identifier": "about",
"name": "About",
"pageRef": "/about",
"weight": 10
},
{
"identifier": "contact",
"name": "Contact",
"pageRef": "/contact",
"weight": 20
}
]
}
}
此示例在多语言站点上查询翻译表时使用 Identifier
方法,如果翻译表中不存在匹配的键,则回退到 name
属性:
<ul>
{{ range .Site.Menus.main }}
<li><a href="{{ .URL }}">{{ or (T .Identifier) .Name }}</a></li>
{{ end }}
</ul>