1

我是 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 }}
4

1 回答 1

6

这是Hugo Template Functions 文档中的一个示例,我认为这意味着您只是缺少括号:

{{ range first 5 (where .Data.Pages "Section" "post") }}
   {{ .Content }}
{{ end }}
于 2016-08-23T05:11:00.273 回答