HUGO
Menu
GitHub 86785 stars Mastodon

ByLanguage

Returns the given page collection sorted by language.

Syntax

PAGES.ByLanguage

Returns

page.Pages

When sorting by language, Hugo orders the page collection using the following priority:

  1. Language weight (ascending)
  2. Date (descending)
  3. LinkTitle (ascending)

This method is rarely, if ever, needed. Page collections that already contain multiple languages, such as those returned by the Rotate, Translations, or AllTranslations methods on a Page object, are already sorted by language weight.

This contrived example aggregates pages from all sites and then sorts them by language:

{{ $p := slice }}
{{ range hugo.Sites }}
  {{ range .Pages }}
    {{ $p = $p | append . }}
  {{ end }}
{{ end }}

{{ range $p.ByLanguage }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}

To sort in descending order:

{{ range $p.ByLanguage.Reverse }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}