Range first producing error "both limit and seq must be provided..."

Hey all, first post so forgive me if I make any faux pas.

I’m trying to modify the hyde-y template to show tags on a post comma-separated. My attempt to do this is below:

{{ range first 1 .Params.tags }}
<a class="label" href="{{ "/tags/" | absURL }}{{ . | urlize }}">{{ . }}</a>
{{ end }}
{{ range after 1 .Params.tags }}
, <a class="label" href="{{ "/tags/" | absURL }}{{ . | urlize }}">{{ . }}</a>
{{ end }}

This produces the desired output (although I have to remove the newlines or I get spaces I don’t want)

When hugo builds the site I get the following error:

ERROR: 2016/02/09 template: partials/modules/page/tags.html:1:15: executing “partials/modules/page/tags.html” at <first 1 .Params.tags>: error calling first: both limit and seq must be provided in partials/modules/page/tags.html

once per page that uses the tags.html

The site seems to come out fine, but I’d like to know if there’s anything I can do to fix or at least suppress this error.

oh, and the hugo version text:

Hugo Static Site Generator v0.15 BuildDate: 2016-02-04T16:57:00Z

Thanks all!

I’m assuming that you have a page where tags isn’t defined. Try wrapping your code with this:

{{ if isset .Params "tags" }}
...
{{ end }}
2 Likes

Should have seen it for myself, that was exactly the problem.

Thanks!

Can anyone elaborate what @moorereason means by…

you have a page where tags isn’t defined.

I’m getting the same error and this problems seems to be answered here on Hugo support in two different ways, with the other post directing more to config.toml. I don’t understand the link between the answers.

My exact error message being…

ERROR: 2016/08/28 20:20:30 template.go:131: template: theme/partials/offers.html:1:9: executing “theme/partials/offers.html” at <first 2 .offer>: error calling first: both limit and seq must be provided in theme/partials/offers.html

I’ve narrow it down to some data files I’m calling in. I’ve used “first” and “last” functions to target the data and display and display some differently. This is the offers.html file that the error message refers to…

{{ range first 2 .offer }}
  <div class="{{ .cols }} p-x-md m-b-lg">
    <p class="lead"><strong>{{ .name }}</strong>. {{ .desc }}. <span class="text-muted">{{ .terms }}</span> {{ .telloc }}</p>
  </div>
{{ end }}

{{ range last 1 .offer }}
  <div class="{{ .cols }} p-x-md m-b-lg">
    <p class="lead"><strong>{{ .name }}</strong>. {{ .desc }}. <span class="text-muted">{{ .terms }}</span> <a href="tel:{{ .telint }}">{{ .telloc }}</a></p>
  </div>
{{ end }}

If I remove “first 1” and “last 2” and just use {{ range .offer }} the errors disappear. The content displays as desired with the first and last functions though?