HUGO
Menu
GitHub 87548 stars Mastodon

Params

返回給定菜單項的 params 屬性。

Syntax

MENUENTRY.Params

Returns

maps.Params

當您在 [站點配置中] 或 在 front matter 中 定義菜單項時,您可以包含 params 鍵來為條目附加額外信息。例如:

menus:
  main:
  - name: About
    pageRef: /about
    weight: 10
  - name: Contact
    pageRef: /contact
    weight: 20
  - name: Hugo
    params:
      rel: external
    url: https://www.hugodoc.com
    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://www.hugodoc.com'
    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://www.hugodoc.com",
            "weight": 30
         }
      ]
   }
}

使用此模板:

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

Hugo 渲染:

<ul>
  <li><a href="/about/">About</a></li>
  <li><a href="/contact/">Contact</a></li>
  <li><a href="https://www.hugodoc.com" rel="external">Hugo</a></li>
</ul>

有關更多信息,請參閱 菜單模板 部分。


Last updated: January 1, 0001
Improve this page