HUGO
Menu
GitHub 87548 stars Mastodon

ByParam

返回给定页面集合按给定参数升序排序。

Syntax

PAGES.ByParam PARAM

Returns

page.Pages

如果 front matter 中不存在给定参数,Hugo 将使用站点配置中匹配的参数(如果存在)。

{{ range .Pages.ByParam "author" }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}

要按降序排序:

{{ range (.Pages.ByParam "author").Reverse }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}

如果目标参数是嵌套的,请使用点表示法访问字段:

{{ range .Pages.ByParam "author.last_name" }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}

Last updated: January 1, 0001
Improve this page