mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
940 B
940 B
title | description | categories | keywords | action | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Reverse | Returns the given menu, reversing the sort order of its entries. |
|
The Reverse
method returns the given menu, reversing the sort order of its 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 in descending order:
<ul>
{{ range .Site.Menus.main.ByName.Reverse }}
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
{{ end }}
</ul>
Hugo renders this to:
<ul>
<li><a href="/services/">Services</a></li>
<li><a href="/contact">Contact</a></li>
<li><a href="/about/">About</a></li>
</ul>