mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-27 22:09:53 +02:00
Merge commit '35dec7c96f7ee3eb17dd444f7067f0c776fb56ae'
This commit is contained in:
51
docs/content/en/methods/menu-entry/Parent.md
Normal file
51
docs/content/en/methods/menu-entry/Parent.md
Normal file
@@ -0,0 +1,51 @@
|
||||
---
|
||||
title: Parent
|
||||
description: Returns the `parent` property of the given menu entry.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related: []
|
||||
returnType: string
|
||||
signatures: [MENUENTRY.Parent]
|
||||
---
|
||||
|
||||
With this menu definition:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[menu]
|
||||
[[menu.main]]
|
||||
name = 'Products'
|
||||
pageRef = '/product'
|
||||
weight = 10
|
||||
|
||||
[[menu.main]]
|
||||
name = 'Product 1'
|
||||
pageRef = '/products/product-1'
|
||||
parent = 'Products'
|
||||
weight = 1
|
||||
|
||||
[[menu.main]]
|
||||
name = 'Product 2'
|
||||
pageRef = '/products/product-2'
|
||||
parent = 'Products'
|
||||
weight = 2
|
||||
{{< /code-toggle >}}
|
||||
|
||||
This template renders the nested menu, listing the `parent` property next each of the child entries:
|
||||
|
||||
```go-html-template
|
||||
<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>
|
||||
```
|
Reference in New Issue
Block a user