GroupBy
语法
PAGES.GroupBy FIELD [SORT]
返回值
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 }}