aboutsummaryrefslogtreecommitdiffhomepage
path: root/docs/content/en/methods/menu/Limit.md
blob: 12263e81137c634b76b4c8a68a35c1a054b978e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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>
```