HUGO
Menu
GitHub 90265 stars Mastodon

GroupByParam

Returns the given page collection grouped by the given parameter in ascending order.
Syntax
PAGES.GroupByParam PARAM [SORT]
Returns
page.PagesGroup

For the optional sort order, specify either asc for ascending order, or desc for descending order.

Use the GroupByParam method to group by a custom field. To group by a reserved field, pass the name of the corresponding Page method to the GroupBy method.

Deprecated in v0.169.0

Passing the name of a reserved field, such as title, to the GroupByParam method is deprecated. Pass the name of the corresponding Page method to the GroupBy method instead, such as GroupBy "Title". Hugo does not log a deprecation warning in every case.

{{ range .Pages.GroupByParam "color" }}
  <p>{{ .Key | title }}</p>
  <ul>
    {{ range .Pages }}
      <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
    {{ end }}
  </ul>
{{ end }}

To sort the groups in descending order:

{{ range .Pages.GroupByParam "color" "desc" }}
  <p>{{ .Key | title }}</p>
  <ul>
    {{ range .Pages }}
      <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
    {{ end }}
  </ul>
{{ end }}