How to paginate post using partial?

Hello Nice people, I want to use pagination by calling a partial. But I can’t figure out how to do it. This is what I have done, and the result showing empty/nill.

Calling the partial:

{{ partial "blog.html" (dict "Paging" true ) }}

This is the blog partial:

{{ $paginator := site.RegularPages }}
{{ if .Paging }}
{{ $paginator = (.Page.Paginate $paginator).Pages }}
{{ end }}

{{ range $paginator }}
{{ .Title }}
{{ end }}

any help will be appreciated.

Hi Somrat,

The DOT in your partial has only .Paging available, not .Page.Paginate. You don’t give the context over to the partial. You need to call the partial like this:

{{ partial "blog.html" (dict "Paging" true "context" .) }}

and then in the partial:

{{ $theDot := .context }}
{{ $paging := .Paging }}
{{ paginator = ($theDot.Page.Paginate) }}
// etc
5 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.