Using multiple .Paginate ranges with Hugo

392 Views Asked by At

I'm struggling in creating multiple ranges using hugo.

 {{ range (.Paginate (where site.RegularPages "Section" "research")).Pages }}
    {{ partial "research-card" .}}
  {{ end }}

  {{ range (.Paginate (where site.RegularPages "Section" "services")).Pages }}
       {{ partial "services-card" .}}
  {{ end }}

I want to use each of these to create cards for different sections however they are in the same html file. The issue I am having is that when I add the second range it removes the cards from the first one and if I create pages for each I get nil variable errors.

Is there a way to use more than one range on the same page in hugo to create a home page that loads different sections?

2

There are 2 best solutions below

0
Mr. Hugo On BEST ANSWER

The error message is pretty clear: It is not supported with two paginagors on one page, “/page/1” then … what do we do with the second? We may make some magic in this department in the future, but that is a big maybe. You will have to figure a way to exclude one or both of the paginators.

Says Bjørn Erik Pedersen here.

0
Jeremie On

You can not use .Paginate with different parameters on the same page. As per the documentation, it can be used only once per page.

If you call .Paginator or .Paginate multiple times on the same page, you should ensure all the calls are identical. Once either .Paginator or .Paginate is called while generating a page, its result is cached, and any subsequent similar call will reuse the cached result. This means that any such calls which do not match the first one will not behave as written.

https://gohugo.io/templates/pagination/