Can you check my understanding of the pagination system?

I’m trying to implement pagination on my site. I want to exclude entries of type “page”.

Here’s what I’ve got: .Paginate (where .Data.Pages "Type" "not in" (slice "page"))

The docs recommend using a variable like {{ $paginator := .Paginate (where .Data.Pages "Type" "not in" (slice "page")) }} and then referencing it later like {{ range $paginator.Pages }}.

However, that poses a problem for me. I’m using a fair number of partials and block templates, so that variable would be lost in subsequent scopes. I could use .Scratch to store it and retrieve it, but I feel like that’s a dirty approach to what I’m about to suggest.

I read the source for the .Paginate function here. It appears to me to not only return the Pager you create, but it sets that as the default pager for the node you’re currently in. So, it appears that if I put <!-- {{ .Paginate (where .Data.Pages "Type" "not in" (slice "page")) }} --> like so, it’ll set the node’s .Paginator to that created one. I’ve put the code in a HTML comment because that code returns an instance of the pager, but I don’t want it to print to the page. In this way, I’m running code but disregarding its return value. Also, I no longer have to worry about passing variables around with .Scratch or otherwise.

This seems valid to me, but I don’t see this approach documented anywhere and I want to make sure I’m not missing some pitfall of this approach.

It is static and can be referenced later with .Paginator.

If you don’t want a variable (not sure why not), you could try:

 {{ _ := .Paginate (where .Data.Pages "Type" "not in" (slice "page")) }}

The “_” variable is (if it works) standard Go syntax to avoid assigning to a variable.

I would say doing a printing of the paginator inside a HTML comment would be much worse than any of the suggested options. But up to you.