Skip to content

Commit 25ce893

Browse files
authored
content: Clarify sort order with PAGE.Rotate
1 parent b398506 commit 25ce893

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

content/en/methods/page/Rotate.md

Lines changed: 26 additions & 17 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,36 +11,45 @@ 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 the current page's language variants, including the current page, while sharing its current version and role:
1931

2032
```go-html-template
21-
{{ with .Rotate "language" }}
22-
{{ range . }}
23-
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
24-
{{ end }}
33+
{{/* Returns languages sorted by weight ascending, then lexicographically ascending */}}
34+
{{ range .Rotate "language" }}
35+
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
2536
{{ end }}
2637
```
2738

28-
To render a list of all versions of the current page, including the current page:
39+
To render a list of the current page's version variants, including the current page, while sharing its current language and role:
2940

3041
```go-html-template
31-
{{ with .Rotate "version" }}
32-
{{ range . }}
33-
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
34-
{{ end }}
42+
{{/* Returns versions sorted by weight ascending, then semantic version descending */}}
43+
{{ range .Rotate "version" }}
44+
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
3545
{{ end }}
3646
```
3747

38-
To render a list of all [roles](g) of the current page, including the current page:
48+
To render a list of the current page's role variants, including the current page, while sharing its current language and version:
3949

4050
```go-html-template
41-
{{ with .Rotate "role" }}
42-
{{ range . }}
43-
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
44-
{{ end }}
51+
{{/* Returns roles sorted by weight ascending, then lexicographically ascending */}}
52+
{{ range .Rotate "role" }}
53+
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
4554
{{ end }}
4655
```

0 commit comments

Comments
 (0)