I am new to Go and Hugo site generator and currently creating a simple theme. I am trying to combine a where
filter along with first
function and I am not able to make it work.
What I want is to get first 10 items in the post
section
{{ range where .Data.Pages "Section" "post" }}
<li><a href="{{.RelPermalink}}">{{.Title}}</a> <em>{{.Summary}}</em></li>
{{ end }}
The above works fine, but how do I make it return only the first 10 items (the below does not work):
{{ range first 10 where .Data.Pages "Section" "post" }}
<li><a href="{{.RelPermalink}}">{{.Title}}</a> <em>{{.Summary}}</em></li>
{{ end }}
Here's an example from the Hugo Template Functions documentation that I think means you're just missing parentheses:
{{ range first 5 (where .Data.Pages "Section" "post") }}
{{ .Content }}
{{ end }}