Merge commit '35dec7c96f7ee3eb17dd444f7067f0c776fb56ae'

This commit is contained in:
Bjørn Erik Pedersen
2023-12-04 15:24:01 +01:00
810 changed files with 24147 additions and 7766 deletions

View File

@@ -0,0 +1,50 @@
---
title: Limit
description: Returns the given menu, limited to the first N entries.
categories: []
keywords: []
action:
related: []
returnType: navigation.Menu
signatures: [MENU.Limit N]
---
The `Limit` method returns the given menu, limited to the first N entries.
Consider this menu definition:
{{< code-toggle file=hugo >}}
[[menu.main]]
name = 'Services'
pageRef = '/services'
weight = 10
[[menu.main]]
name = 'About'
pageRef = '/about'
weight = 20
[[menu.main]]
name = 'Contact'
pageRef = '/contact'
weight = 30
{{< /code-toggle >}}
To sort the entries by name, and limit to the first 2 entries:
```go-html-template
<ul>
{{ range .Site.Menus.main.ByName.Limit 2 }}
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
{{ end }}
</ul>
```
Hugo renders this to:
```html
<ul>
<li><a href="/about/">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
```