I have a weird error where most builds succeed, but then a few fail with the message:
execute of template failed: template: products/keywords.html:6:14: executing "products/keywords.html" at <.Paginate>: error calling Paginate: invoked multiple times with different arguments
I’m not sure what I’m doing wrong. How should I troubleshoot this error? I can only see .Paginate
being invoked one time on products/keywords.html
. I also use the same pagination partial on products/list.html
. As a test, I removed pagination from products/list.html
but the error persists so I assume there is no conflict between using pagination in both templates.
Content
|-- products
|-- _index.md
|-- product1.md
|-- product2.md
|-- cars [layout = "keywords"]
|-- _index.md
Layout/products/keywords.html
{{$related := .Paginate ((where site.RegularPages "Section" .Section).Related .)}}
{{range $related.Pages}}
{{.Title}}
{{end}}
{{partial "pagination.html" .}}
partials/pagination.html [src]
{{ $pag := $.Paginator }}
{{ if gt $pag.TotalPages 1 }}
{{ $.Scratch.Set "dot_rendered" false }}
<nav aria-label="page navigation">
<ul class="pagination">
<!-- Don't show on 1st and 2nd page -->
{{ if and (ne $pag.PageNumber 1) (ne $pag.PageNumber 2) }}
<li class="page-item"><a href="{{ $pag.First.URL }}" rel="first" class="page-link">« First</a></li>
{{ end }}
{{ if $pag.HasPrev }}
<li class="page-item"><a href="{{ $pag.Prev.URL }}" rel="prev" class="page-link">‹ Prev</a></li>
{{ end }}
{{ range $pag.Pagers }}
{{ if eq . $pag }} <!-- Current Page -->
<li class="page-item active"><a href="{{ .URL }}" class="page-link">{{ .PageNumber }}</a></li>
{{ else if and (ge .PageNumber (sub $pag.PageNumber 2)) (le .PageNumber (add $pag.PageNumber 2)) }}
{{ $.Scratch.Set "dot_rendered" false }} <!-- Render prev 2 page and next 2 pages -->
<li class="page-item"><a href="{{ .URL }}" class="page-link">{{ .PageNumber }}</a></li>
{{ else if eq ($.Scratch.Get "dot_rendered") false }} <!-- render skip pages -->
{{ $.Scratch.Set "dot_rendered" true }}
<li class="page-item disabled"><a class="page-link">...</a></li>
{{ end }}
{{ end }}
{{ if $pag.HasNext }}
<li class="page-item"><a href="{{ $pag.Next.URL }}" rel="next" class="page-link">Next ›</a></li>
{{ end }}
<!-- Don't show on last and 2nd last page -->
{{ if and (ne $pag.PageNumber $pag.TotalPages) ((ne $pag.PageNumber (sub $pag.TotalPages 1))) }}
<li class="page-item"><a href="{{ $pag.Last.URL }}" rel="last" class="page-link">Last »</a></li>
{{ end }}
</ul>
</nav>
{{ end }}