Issues with .Paginate

Hey guys I’m running into an issue when using .Paginate. I’m trying to create a collection of pages by making a union of two sections and then applying pagination to it.

It’s very weird since the collection of both sections works just fine it’s when I try to paginate them that .Paginate seems to just use the current sections pages instead of using the collection I provide it with.

Here is my code:

{{ define "main" }}
{{/* Get all pages from press-release and news sections */}}
      {{ $pressReleases := where site.RegularPages.ByDate.Reverse "Section" "press-release" }}
      {{ $news := .RegularPagesRecursive.ByDate.Reverse }}

      {{/* Combine and sort pages */}}
      {{ $pages := sort (union $news $pressReleases) ".Date" "desc" }}

      {{/* Paginate the sorted pages */}}
      {{ $paginator := .Paginate $pages.ByDate.Reverse }}

      <h1>Press Releases - Pages({{len $pressReleases}})</h1>
      {{range $pressReleases}}
      <p>{{ .Title }}</p>
      {{ end }}

      <h1>News - Pages({{len $news}})</h1>
      {{range $news}}
      <p>{{ .Title }}</p>
      {{ end }}
      
      <h1>Paginator Pages - {{$paginator.Pages}}</h1>
      {{range $paginator.Pages}}
      <p>{{ .Title }}</p>
      {{ end }}

      <h1>Merged Pages - {{$pages}}</h1>
      {{ range $pages }}
        <p>{{ .Title }}</p>
      {{ end }}

      <p> Total merged pages: {{ len $pages }} </p>
      <p> Pages in current pagination: {{ len $paginator.Pages }} </p>
{{ end }}

And here is the output for debugging purposes:


Press Releases - Pages(15)

Rewst Unveils Details and Registration for FLOW 2025, the Vendor-Agnostic Automation Conference for MSPs

Rewst Empowers MSPs to Monetize Automation with First in a Series of Client-Facing Integrations

Rewst Unveils First Three Prebuilt Apps for App Builder

Rewst Raises $45 Million to Accelerate Platform Innovation and Community-Led Growth

Synnex Australia and Rewst Forge Strategic Partnership to Elevate MSP Automation

Rewst Extends Open, Vendor-Agnostic Vision with Expanded Integration Library and Custom Integration Builder

Introducing FLOW, a vendor-agnostic automation conference for MSPs, hosted by Rewst

Rewst Raises $31 Million Series B to Extend Leadership in MSP Automation Market

Rewst Unveils Low-Code App Platform, Enabling MSPs to Extend Automations with Branded Front-End Experiences

Rewst releases 50 pre-built automations, helping MSPs realize immediate business value

Pax8 and Rewst Partner to Provide MSPs with Purpose-Built Robotic Process Automation Platform

Meet the ROC: Tim Fournet, Cratemaster

Rewst Raises $21.5 Million Series A to Bring Automation to MSPs

Rewst Secures $4 Million Funding Led by TDF Ventures

Florida Funders Leads $2.5MM Seed Investment in Rewst

News - Pages(5)

Rewst CEO, Aharon Chernin, Named Tampa Bay Inno Fire Awards Honoree

Tampa serial entrepreneur raises $4M

MSP Automation Software Startup Rewst Raises $4M; Plans RPA Expansion

New Venture ‘Rewst’ Aims to Make Automation More Accessible for MSPs

Startup Rewst Closes $2.5M Seed Funding To Bring RPA To MSPs

Paginator Pages - Pages(5)

Rewst CEO, Aharon Chernin, Named Tampa Bay Inno Fire Awards Honoree

Tampa serial entrepreneur raises $4M

MSP Automation Software Startup Rewst Raises $4M; Plans RPA Expansion

New Venture ‘Rewst’ Aims to Make Automation More Accessible for MSPs

Startup Rewst Closes $2.5M Seed Funding To Bring RPA To MSPs

Merged Pages - Pages(20)

Rewst Unveils Details and Registration for FLOW 2025, the Vendor-Agnostic Automation Conference for MSPs

Rewst Empowers MSPs to Monetize Automation with First in a Series of Client-Facing Integrations

Rewst Unveils First Three Prebuilt Apps for App Builder

Rewst Raises $45 Million to Accelerate Platform Innovation and Community-Led Growth

Synnex Australia and Rewst Forge Strategic Partnership to Elevate MSP Automation

Rewst Extends Open, Vendor-Agnostic Vision with Expanded Integration Library and Custom Integration Builder

Introducing FLOW, a vendor-agnostic automation conference for MSPs, hosted by Rewst

Rewst Raises $31 Million Series B to Extend Leadership in MSP Automation Market

Rewst Unveils Low-Code App Platform, Enabling MSPs to Extend Automations with Branded Front-End Experiences

Rewst releases 50 pre-built automations, helping MSPs realize immediate business value

Pax8 and Rewst Partner to Provide MSPs with Purpose-Built Robotic Process Automation Platform

Meet the ROC: Tim Fournet, Cratemaster

Rewst Raises $21.5 Million Series A to Bring Automation to MSPs

Rewst CEO, Aharon Chernin, Named Tampa Bay Inno Fire Awards Honoree

Tampa serial entrepreneur raises $4M

Rewst Secures $4 Million Funding Led by TDF Ventures

MSP Automation Software Startup Rewst Raises $4M; Plans RPA Expansion

New Venture ‘Rewst’ Aims to Make Automation More Accessible for MSPs

Startup Rewst Closes $2.5M Seed Funding To Bring RPA To MSPs

Florida Funders Leads $2.5MM Seed Investment in Rewst

Total merged pages: 20

Pages in current pagination: 5


Any clues as to what I am doing wrong? Thanks.

https://gohugo.io/templates/pagination/

So I suspect you are first invoking one or the other somewhere else.

Thats literally the whole code of the list page template, I’m not calling pagination on it anywhere else :grimacing:

Hugo version in case that helps:

hugo v0.143.1+extended+withdeploy darwin/arm64 BuildDate=2025-02-04T08:57:38Z VendorInfo=brew

This was working in Hugo v0.120 or lower IIRC

Can you share your repo?

I cannot but I’ll make a repo where I can replicate the issue, thanks @jmooring

I stand corrected, you were right. We are using this in our head in order to have unique title tags for paginated pages:

{{ if .IsNode }}
  {{ if .Paginator }}
    {{ $pageNumber = printf " - Page %d" .Paginator.PageNumber }}
  {{ end }}
{{ end }}

If I get rid of it it works FML, now to see how to solve this conundrum.

Thanks for pointing me in the right direction (as usual) @jmooring you are the Hugo GOAT :trophy:

1 Like

Thanks @tyco again @jmooring showing us how its done :muscle:

Thanks guys

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