Error using first: both limit and seq must be provided

I’m getting this error:

ERROR 2018/04/25 18:14:40 Error while rendering "home" in "": template: /Users/rcogley/dev/eSolia_2018/layouts/_default/home.html:248:23: executing "main" at <first 6 .Site.Taxono...>: error calling first: both limit and seq must be provided
WARN 2018/04/25 18:14:40 template: /Users/rcogley/dev/eSolia_2018/layouts/_default/home.html:248:23: executing "main" at <first 6 .Site.Taxono...>: error calling first: both limit and seq must be provided

My template has this:

<ul class="has-padding-t-l">
{{ range first 5 .Site.Taxonomies.series.top1 }}
<li class="link list-has-no-style"><a class="link" href="{{ .Permalink }}">{{ .Page.Title | markdownify }}</a><span class="is-italic">&nbsp;&mdash;&nbsp;{{ .Date.Format "02 Jan, 2006" }}</span></li>
{{ end }}
</ul>

A handful of pages have the relevant “series” set in frontmatter. Not all. It’s actually working to display content and the error does not appear to be fatal, so I am not sure what I am doing wrong.

But, does anyone know what the error means by “both limit and seq must be provided”? How do I change my range statement to fix the error?

This appears to work but gives an error “can’t iterate over nil”.

<ul class="has-padding-t-l">
{{ range first 6 (where .Site.Taxonomies.series.top1.Pages "Section" "page") }}
  <li class="link list-has-no-style"><a class="link" href="{{ .Permalink }}">{{ .Title | markdownify }}</a><span class="is-italic">&nbsp;&mdash;&nbsp;{{ .Date.Format "02 Jan, 2006" }}</span></li>
{{ end }}
</ul>

Try using with here:

{{ with .Site.Taxonomies.series.top1 }}
    {{ range first 5 . }}
        ...
    {{ end }}
{{ end }}

The error is for the cases you said where series front-matter is absent… so the first was seeing the second argument as nil in those cases.

5 Likes

@kaushalmodi, thanks so much, that worked perfectly!

I thought putting the name of the series at the end did limit it, so that the range would just be working on pages that have that set.