'Prev' & 'Next' pager weird values

Like in the example, I generate the latest 10 posts like this:

{{ $paginator := .Paginate (where .Data.Pages.ByDate.Reverse "Section" "p") }}
{{ range $paginator.Pages }}

I’m trying to get the links for the pagers with {{ $paginator.Prev }} and {{ $paginator.Next }} When there is either no previous or next page, I get the expected value of <nil>. But for example this is what the pager for page 2 returns: {2 0xc2082b0e70}.

What am I doing wrong? Other parameters like $paginator.PageNumber or $paginator.TotalPages work fine.


1 Like

You probably need to use {{$paginator.Next.URL}}. You can take a look at how I’ve done simple pagination in a theme: https://github.com/dplesca/purehugo/blob/master/layouts/partials/pagination.html

Then I get the error message

panic: runtime error: invalid memory address or nil pointer dereference [recovered]

Maybe it’s because of the “where”-filtering? I don’t even need the full urls, just number values for the next/prev page would be totally sufficient :slight_smile:

You must wrap them in HasNext and HasPrev. See the builtin paginator template for an example:


1 Like

Thank you very much!