Parent
Syntax
MENUENTRY.Parent
Returns
string
使用此菜单定义:
hugo.
menu:
main:
- name: 产品
pageRef: /product
weight: 10
- name: 产品1
pageRef: /products/product-1
parent: 产品
weight: 1
- name: 产品2
pageRef: /products/product-2
parent: 产品
weight: 2
[menu]
[[menu.main]]
name = '产品'
pageRef = '/product'
weight = 10
[[menu.main]]
name = '产品1'
pageRef = '/products/product-1'
parent = '产品'
weight = 1
[[menu.main]]
name = '产品2'
pageRef = '/products/product-2'
parent = '产品'
weight = 2
{
"menu": {
"main": [
{
"name": "产品",
"pageRef": "/product",
"weight": 10
},
{
"name": "产品1",
"pageRef": "/products/product-1",
"parent": "产品",
"weight": 1
},
{
"name": "产品2",
"pageRef": "/products/product-2",
"parent": "产品",
"weight": 2
}
]
}
}
此模板呈现了嵌套菜单,列出了每个子条目旁边的parent
属性:
<ul>
{{ range .Site.Menus.main }}
<li>
<a href="{{ .URL }}">{{ .Name }}</a>
{{ if .HasChildren }}
<ul>
{{ range .Children }}
<li><a href="{{ .URL }}">{{ .Name }}</a> ({{ .Parent }})</li>
{{ end }}
</ul>
{{ end }}
</li>
{{ end }}
</ul>