[SOLVED] Paginating the full list of pages

I am still struggling with listing the full content of the site, minus pages in content/page and content/instagrams.

So far I can list what I need like this:

{{ $posts := (where .Site.Pages.ByPublishDate.Reverse ".Params.unlisted" "!=" true) }}
{{ range .Paginate $posts }}
	{{ .Render "summary"}}
{{ end }}

The problem is it will return an error saying error calling Paginate: Paginators not supported for pages of type "page"

Two questions here:

  1. Do I need to enter in the front matter that specific files are posts? I checked and I haven’t been doing that.

  2. Still, shouldn’t it be possible to list all the content and paginate it accordingly?

You may want to use .Site.RegularPages.ByPublishDate (up to you), but that is not the cause of this error.

You are using this in a template that is invoked for a list page (home page, section page, taxonomy list, taxonomy term).

It is of course hard for me to guess, but if the above is an extract from single.html, that does not work.

Yes I was using a sort of single.html, specifying the layout: “allposts” in the frontmatter.

If I can’t call that layout from a page, what is the right way to do it?

(in case anyone wishes to take a look at the source code)

I don’t know about the right way, but I may have a bad one for you. (not tested)

  1. Create a new directory within your content. (you’ve got a new section)
  2. Add a _index.md in it so you can assign it a title, a url and most importantly your custom, layout.
  3. Then test your current code as is. Your custom layout being on a list template, the .Paginate object may be available to you. That is if .Paginate is even designed to work with .Site.Data.Pages.
  4. If it works, you can take a shower cuz this is dirty. If it doesn’t that’s probably for the best.

The cleanest way is to create a section (name it “allposts” or something).

Thanks guys, I got it to work by creating the section.

For everyone else finding this posts, here is the final snippet of code

{{ range (.Paginate (where .Site.Pages.ByPublishDate.Reverse ".Params.unlisted" "!=" true) 9).Pages }}
	{{ .Render "summary"}}
{{ end }}

Keep in mind I am using a .Params.unlisted that is specific to my frontmatter and use-case. Also, there has to be at least a _index.md file in the new section for this to work.

1 Like

A post was split to a new topic: Question about range (.Paginate (where .Site.RegularPages “Type” “blog”))