group.md (924B)
1 ---
2 title: group
3 description: "`group` groups a list of pages."
4 date: 2018-09-14
5 categories: [functions]
6 menu:
7 docs:
8 parent: "functions"
9 keywords: [collections]
10 signature: ["PAGES | group KEY"]
11 hugoversion: "0.49"
12 ---
13
14 {{< code file="layouts/partials/groups.html" >}}
15 {{ $new := .Site.RegularPages | first 10 | group "New" }}
16 {{ $old := .Site.RegularPages | last 10 | group "Old" }}
17 {{ $groups := slice $new $old }}
18 {{ range $groups }}
19 <h3>{{ .Key }}{{/* Prints "New", "Old" */}}</h3>
20 <ul>
21 {{ range .Pages }}
22 <li>
23 <a href="{{ .Permalink }}">{{ .Title }}</a>
24 <div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
25 </li>
26 {{ end }}
27 </ul>
28 {{ end }}
29 {{< /code >}}
30
31 The page group you get from `group` is of the same type you get from the built-in [group methods](/templates/lists#group-content) in Hugo. The above example can even be [paginated](/templates/pagination/#list-paginator-pages).