Control pagination and page collections from baseof.html

Example

git clone --single-branch -b hugo-forum-topic-37643 https://github.com/jmooring/hugo-testing hugo-forum-topic-37643
cd hugo-forum-topic-37643
hugo server

To verify that we’re not clobbering our pagination parameters:

  • The articles list page will show 3 articles per pager, by title
  • The books list page will show 5 books per pager, by title (reversed)
  • The films list page will show 7 films per pager, by date
  • The quotations list page will not be paginated

layouts/_default/baseof.html

At the top of the file we define our pagination strategy, by section, for the entire site. This means that later on in the file we have access to the paginator properties (e.g., the current pager number, total number of pagers, etc.).

layouts/_default/list.html

Uses a conditional to define the page collection, mirroring the logic used in layouts/_default/baseof.html.

Comments

While this is functional, it makes pagination a “site wide” feature, instead of something you can just add when needed on any given list page. For example, with this approach, you cannot easily split an article into multiple pages using this method.

Related

https://discourse.gohugo.io/t/37494/4
https://github.com/gohugoio/hugo/issues/4507

5 Likes