参数
语法
MENUENTRY.Params
返回
maps.Params
当您在站点配置或前言中定义菜单项时,您可以包含一个 params
键以将其他信息附加到该项。例如
hugo。
menus:
main:
- name: About
pageRef: /about
weight: 10
- name: Contact
pageRef: /contact
weight: 20
- name: Hugo
params:
rel: external
url: https://gohugo.com.cn
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.com.cn'
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.com.cn",
"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://gohugo.com.cn" rel="external">Hugo</a></li>
</ul>
有关详细信息,请参阅菜单模板部分。