mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
Merge commit '35dec7c96f7ee3eb17dd444f7067f0c776fb56ae'
This commit is contained in:
67
docs/content/en/methods/menu-entry/Children.md
Normal file
67
docs/content/en/methods/menu-entry/Children.md
Normal file
@@ -0,0 +1,67 @@
|
||||
---
|
||||
title: Children
|
||||
description: Returns a collection of child menu entries, if any, under the given menu entry.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/menu-entry/HasChildren
|
||||
returnType: navigation.Menu
|
||||
signatures: [MENUENTRY.Children]
|
||||
---
|
||||
|
||||
Use the `Children` method when rendering a nested menu.
|
||||
|
||||
With this site configuration:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[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 >}}
|
||||
|
||||
And this template:
|
||||
|
||||
```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></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
```
|
||||
|
||||
Hugo renders this HTML:
|
||||
|
||||
```html
|
||||
<ul>
|
||||
<li>
|
||||
<a href="/products/">Products</a>
|
||||
<ul>
|
||||
<li><a href="/products/product-1/">Product 1</a></li>
|
||||
<li><a href="/products/product-2/">Product 2</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
```
|
Reference in New Issue
Block a user