HUGO
Menu
GitHub 87548 stars Mastodon

GroupBy

返回给定页面集合按给定字段升序分组。

Syntax

PAGES.GroupBy FIELD [SORT]

Returns

page.PagesGroup

对于可选排序顺序,指定 asc 表示升序,或 desc 表示降序。

{{ range .Pages.GroupBy "Section" }}
  <p>{{ .Key }}</p>
  <ul>
    {{ range .Pages }}
      <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
    {{ end }}
  </ul>
{{ end }}

要按降序对组排序:

{{ range .Pages.GroupBy "Section" "desc" }}
  <p>{{ .Key }}</p>
  <ul>
    {{ range .Pages }}
      <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
    {{ end }}
  </ul>
{{ end }}

Last updated: January 1, 0001
Improve this page