Paginate listing inside a shortcode

I’m trying to use a shortcode to list posts matching a certain query,and the following works:

{{ $posts := (where $.Site.Pages ".Params.article_source" "in" (.Get "sources") ) }}

{{ range $posts }}
	{{ .Render "summary" }}
{{ end }}

But it breaks when I try to add pagination:

{{ $posts := (where $.Site.Pages ".Params.article_source" "in" (.Get "sources") ) }}
{{ $paginator := (.Paginate $posts) }}

{{ range $paginator.pages }}
{{ .Render "summary" }}
{{ end }}
Error: Error building site: "/Users/brunoamaral/Labs/gregory/content/physicaltherapists/index.md:55:1": failed to render shortcode "list-by": failed to process shortcode: "/Users/brunoamaral/Labs/gregory/layouts/shortcodes/list-by.html:2:18": execute of template failed: template: shortcodes/list-by.html:2:18: executing "shortcodes/list-by.html" at <.Paginate>: can't evaluate field Paginate in type *hugolib.ShortcodeWithPage

Is this even possible or am I barking up the wrong tree ?

Yeah, that one.

This feature is currently only supported on homepage and list pages.

https://gohugo.io/templates/pagination/#list-paginator-pages

For anyone with the same problem, the workaround is to create a layout page with something like this:

<div class="col-12">{{ .Content }}</div>
{{ $posts := (where $.Site.Pages ".Params.article_source" "in" "PEDro APTA The Lancet BioMedCentral Scielo" ) }}
{{ $paginator := (.Paginate $posts).Pages }}

{{ range $paginator }}
{{ .Render "summary" }}
{{ end }}

then on the frontmatter add: layout: list-bysources or whichever is the layout file you created. The file should be _index.md or _index.html

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