mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-26 22:04:32 +02:00
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
``` git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash ``` Closes #11925
This commit is contained in:
51
docs/content/en/methods/menu/Reverse.md
Normal file
51
docs/content/en/methods/menu/Reverse.md
Normal file
@@ -0,0 +1,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>
|
||||
```
|
Reference in New Issue
Block a user