HasChildren
Reports whether the given menu entry has child menu entries.
Syntax
MENUENTRY.HasChildren
Returns
bool
Use the HasChildren
method when rendering a nested menu.
With this site configuration:
[menus]
[[menus.main]]
name = 'Products'
pageRef = '/product'
weight = 10
[[menus.main]]
name = 'Product 1'
pageRef = '/products/product-1'
parent = 'Products'
weight = 1
[[menus.main]]
name = 'Product 2'
pageRef = '/products/product-2'
parent = 'Products'
weight = 2
And this 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:
<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>
Last updated:
March 5, 2025
:
content: Remove "related" array from function and method pages (2fcd21ee5)
Improve this page