Skip to content

Commit 926d959

Browse files
committed
content: Clarify sort order with PAGE.Rotate
1 parent d9a95fe commit 926d959

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

content/en/methods/page/Rotate.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Rotate
3-
description: Returns a collection of pages that vary along the specified dimension while sharing the current page's values for the other dimensions, including the current page, sorted by the dimension's weight.
3+
description: Returns a collection of pages that vary along the specified dimension while sharing the current page's values for the other dimensions, including the current page, sorted by the dimension's default sort order.
44
categories: []
55
keywords: []
66
params:
@@ -11,33 +11,48 @@ params:
1111

1212
{{< new-in 0.153.0 />}}
1313

14-
The `Rotate` method on a `Page` object returns a collection of pages that vary along the specified [dimension](g), while holding the other dimensions constant. The result includes the current page and is sorted by the dimension's weight. For example, rotating along `language` returns all language variants that share the current page's version and role.
14+
The rotate method on a page object returns a collection of pages that vary along the specified [dimension](g), while holding the other dimensions constant. The result includes the current page and is sorted according to the rules of the specified dimension. For example, rotating along [language](g) returns all language variants that share the current page's [version](g) and [role](g).
1515

1616
The `DIMENSION` argument must be one of `language`, `version`, or `role`.
1717

18-
To render a list of all translations of the current page, including the current page:
18+
## Sort order
19+
20+
Use the following rules to understand how Hugo sorts the collection returned by the `Rotate` method.
21+
22+
| Dimension | Primary Sort | Secondary Sort |
23+
| :--- | :--- | :--- |
24+
| Language | Weight ascending | Lexicographical ascending |
25+
| Version | Weight ascending | Semantic version descending |
26+
| Role | Weight ascending | Lexicographical ascending |
27+
28+
## Examples
29+
30+
To render a list of all versions of the current page, use the following code block.
1931

2032
```go-html-template
21-
{{ with .Rotate "language" }}
33+
{{/* Returns versions sorted by weight ascending, then semantic version descending */}}
34+
{{ with .Rotate "version" }}
2235
{{ range . }}
2336
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
2437
{{ end }}
2538
{{ end }}
2639
```
2740

28-
To render a list of all versions of the current page, including the current page:
41+
To render a list of all translations of the current page, use the following code block.
2942

3043
```go-html-template
31-
{{ with .Rotate "version" }}
44+
{{/* Returns languages sorted by weight ascending, then lexicographically ascending */}}
45+
{{ with .Rotate "language" }}
3246
{{ range . }}
3347
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
3448
{{ end }}
3549
{{ end }}
3650
```
3751

38-
To render a list of all [roles](g) of the current page, including the current page:
52+
To render a list of all roles of the current page, use the following code block.
3953

4054
```go-html-template
55+
{{/* Returns roles sorted by weight ascending, then lexicographically ascending */}}
4156
{{ with .Rotate "role" }}
4257
{{ range . }}
4358
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>

0 commit comments

Comments
 (0)