Params 参数

Params 参数


Returns the `params` property of the given menu entry. 返回给params定菜单项的属性。

When you define menu entries [in site configuration] or [in front matter], you can include a params key to attach additional information to the entry. For example:

当你在站点配置或前言中定义菜单项时,你可以包含一个params键来将附加信息附加到条目中。例如:

hugo.
     
menus:
  main:
  - name: About
    pageRef: /about
    weight: 10
  - name: Contact
    pageRef: /contact
    weight: 20
  - name: Hugo
    params:
      rel: external
    url: https://gohugo.io
    weight: 30
[menus]
[[menus.main]]
    name = 'About'
    pageRef = '/about'
    weight = 10
[[menus.main]]
    name = 'Contact'
    pageRef = '/contact'
    weight = 20
[[menus.main]]
    name = 'Hugo'
    url = 'https://gohugo.io'
    weight = 30
    [menus.main.params]
      rel = 'external'
{
   "menus": {
      "main": [
         {
            "name": "About",
            "pageRef": "/about",
            "weight": 10
         },
         {
            "name": "Contact",
            "pageRef": "/contact",
            "weight": 20
         },
         {
            "name": "Hugo",
            "params": {
               "rel": "external"
            },
            "url": "https://gohugo.io",
            "weight": 30
         }
      ]
   }
}

With this template:

使用此模板:

<ul>
  {{ range .Site.Menus.main }}
    <li>
      <a href="{{ .URL }}" {{ with .Params.rel }}rel="{{ . }}"{{ end }}>
        {{ .Name }}
      </a>
    </li>
  {{ end }}
</ul>

Hugo renders:

Hugo 渲染:

<ul>
  <li><a href="/about/">About</a></li>
  <li><a href="/contact/">Contact</a></li>
  <li><a href="https://gohugo.io" rel="external">Hugo</a></li>
</ul>

See the menu templates section for more information.