Debian Codegraph @

docs/content/en/methods/pages/ByWeight.md

raw
1 ---
2 title: ByWeight
3 description: Returns the given page collection sorted by weight in ascending order.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: page.Pages
9 signatures: [PAGES.ByWeight]
10 ---
11
12 Assign a [weight](g) to a page using the `weight` field in front matter. The weight must be a non-zero integer. Lighter items float to the top, while heavier items sink to the bottom. Unweighted or zero-weighted pages are placed at the end of the collection.
13
14 ```go-html-template
15 {{ range .Pages.ByWeight }}
16 <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
17 {{ end }}
18 ```
19
20 To sort in descending order:
21
22 ```go-html-template
23 {{ range .Pages.ByWeight.Reverse }}
24 <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
25 {{ end }}
26 ```