Identifier (标识符)

Identifier (标识符)


Returns the `identifier` property of the given menu entry. 返回给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.

该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
         }
      ]
   }
}

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:

此示例在多语言网站上查询翻译表时使用该方法,如果翻译表中不存在匹配的键,则Identifier返回该属性:name

<ul>
  {{ range .Site.Menus.main }}
    <li><a href="{{ .URL }}">{{ or (T .Identifier) .Name }}</a></li>
  {{ end }}
</ul>

在上面的菜单定义中,请注意,identifier仅当两个或多个菜单条目具有相同的名称,或者使用翻译表本地化名称时,才需要该属性。