Params
Syntax
MENUENTRY.Params
Returns
maps.Params
在站点配置或正文中定义菜单项时,你可以包含一个params
键来附加额外的信息给这个条目。例如:
hugo.
menu:
main:
- name: 关于
pageRef: /about
weight: 10
- name: 联系我们
pageRef: /contact
weight: 20
- name: Hugo
params:
rel: external
url: https://gohugo.io
weight: 30
[menu]
[[menu.main]]
name = '关于'
pageRef = '/about'
weight = 10
[[menu.main]]
name = '联系我们'
pageRef = '/contact'
weight = 20
[[menu.main]]
name = 'Hugo'
url = 'https://gohugo.io'
weight = 30
[menu.main.params]
rel = 'external'
{
"menu": {
"main": [
{
"name": "关于",
"pageRef": "/about",
"weight": 10
},
{
"name": "联系我们",
"pageRef": "/contact",
"weight": 20
},
{
"name": "Hugo",
"params": {
"rel": "external"
},
"url": "https://gohugo.io",
"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/">关于</a></li>
<li><a href="/contact/">联系我们</a></li>
<li><a href="https://gohugo.io" rel="external">Hugo</a></li>
</ul>
请查看菜单模板部分获取更多信息。
[在站点配置中}: /content-management/menus/