我是 Go 和 Hugo 站点生成器的新手,目前正在创建一个简单的主题。我正在尝试将where
过滤器与first
功能结合起来,但我无法使其工作。
我想要的是获得该post
部分的前 10 个项目
{{ range where .Data.Pages "Section" "post" }}
<li><a href="{{.RelPermalink}}">{{.Title}}</a> <em>{{.Summary}}</em></li>
{{ end }}
以上工作正常,但我如何让它只返回前 10 项(以下不起作用):
{{ range first 10 where .Data.Pages "Section" "post" }}
<li><a href="{{.RelPermalink}}">{{.Title}}</a> <em>{{.Summary}}</em></li>
{{ end }}