标识符
Syntax
MENUENTRY.Identifier
Returns
string
Identifier
方法返回菜单项的identifier
属性。如果你自动定义了菜单项,则返回页面的部分。
hugo.
menu:
main:
- identifier: about
name: About
pageRef: /about
weight: 10
- identifier: contact
name: Contact
pageRef: /contact
weight: 20
[menu]
[[menu.main]]
identifier = 'about'
name = 'About'
pageRef = '/about'
weight = 10
[[menu.main]]
identifier = 'contact'
name = 'Contact'
pageRef = '/contact'
weight = 20
{
"menu": {
"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>