blob: a3fe09dce3071bed439e5290125c2fd5c3f34a36 (
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
51
|
---
title: Reverse
description: Returns the given menu, reversing the sort order of its entries.
categories: []
keywords: []
action:
related: []
returnType: navigation.Menu
signatures: [MENU.Reverse]
---
The `Reverse` method returns the given menu, reversing the sort order of its entries.
Consider this menu definition:
{{< code-toggle file=hugo >}}
[[menus.main]]
name = 'Services'
pageRef = '/services'
weight = 10
[[menus.main]]
name = 'About'
pageRef = '/about'
weight = 20
[[menus.main]]
name = 'Contact'
pageRef = '/contact'
weight = 30
{{< /code-toggle >}}
To sort the entries by name in descending order:
```go-html-template
<ul>
{{ range .Site.Menus.main.ByName.Reverse }}
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
{{ end }}
</ul>
```
Hugo renders this to:
```html
<ul>
<li><a href="/services/">Services</a></li>
<li><a href="/contact">Contact</a></li>
<li><a href="/about/">About</a></li>
</ul>
```
|