[SOLVED ]A Paginator was previously built for this Node

I’m trying to display certain blocks of html depending on whether it’s the homepage or not.

To do that, I’m using the following:

{{ if eq .Paginator.PageNumber 1 }} <h2 class="only-small align-center">Stories</h2> (...) {{ end }}

However, I sometimes get the error: “a Paginator was previously built for this Node”. I’m guessing this happens because I can only call .Paginator once per page. If so, what’s the right way to do this check?

Update: I’m now trying to use {{ if .IsHome }} but no luck. Maybe because the instruction is inside a partial.

You can call .Paginator as many times you want – but there is a ordering issue here that you must look into.

  • You have called .Paginator (which uses .Data.Pages)
  • Then you have called .Paginate with a custom page selection

The selection is static, so you cannot change your mind.

@bep I have been trying to understand this issue and I still have doubts.

In fact I do have a .Paginate after that code:

{{ if eq .Paginator.PageNumber 1 }}
	<h2 class="only-small align-center">Latest post</h2>
{{ end }}
{{ range (.Paginate (where .Data.Pages "Type" "post") 1).Pages }}
	<div class="mini-posts only-small">
	<article class="mini-post stories only-small">
			<p>{{ .Date.Format "January 2, 2006" }}</p>
		<a href="{{ .Permalink }}" class="image mini-featured-image" style="background-image: url('{{ .Site.BaseURL }}{{ .Params.featured_image }}'); background-position: 40% 40%;"><h3 style="background-color: rgba(255,255,255,0.7)">{{ .Title }}</h3></a>
{{ end }}

There is yet another instance of {{ range }}, with the same query, in the index. Yet from what you’re telling me, this will cause conflicts.

What is then the correct approach?

Create the paginator before its used, and put it into a variable.

1 Like

thank you for clearing that up :slight_smile: