| 1 |
--- |
| 2 |
title: GroupByParam |
| 3 |
description: Returns the given page collection grouped by the given parameter in ascending order. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: page.PagesGroup |
| 9 |
signatures: ['PAGES.GroupByParam PARAM [SORT]'] |
| 10 |
--- |
| 11 |
|
| 12 |
{{% include "/_common/methods/pages/group-sort-order.md" %}} |
| 13 |
|
| 14 |
```go-html-template |
| 15 |
{{ range .Pages.GroupByParam "color" }} |
| 16 |
<p>{{ .Key | title }}</p> |
| 17 |
<ul> |
| 18 |
{{ range .Pages }} |
| 19 |
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li> |
| 20 |
{{ end }} |
| 21 |
</ul> |
| 22 |
{{ end }} |
| 23 |
``` |
| 24 |
|
| 25 |
To sort the groups in descending order: |
| 26 |
|
| 27 |
```go-html-template |
| 28 |
{{ range .Pages.GroupByParam "color" "desc" }} |
| 29 |
<p>{{ .Key | title }}</p> |
| 30 |
<ul> |
| 31 |
{{ range .Pages }} |
| 32 |
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li> |
| 33 |
{{ end }} |
| 34 |
</ul> |
| 35 |
{{ end }} |
| 36 |
``` |