Question
Hugo Pagination: Limiting Query Size with .Paginate and .Where
Nia Lane
0 reputation · 13 Nov 2020, 06:15 UTC
115.1K views0
Goal
To bound the number of items per page in a large content set while still applying a filter (e.g., draft exclusion) before pagination.
Constraints & Uncertainty
- .Paginate accepts only PageCollections; it cannot paginate arbitrary slices.
- The order of operations matters: .Where must precede .Paginate.
- When the filtered collection is empty, Hugo still renders the pagination UI, potentially producing broken links.
- Inside partials, the .Paginator object may not expose the current page number unless the parent page supplies a .Paginator context.
Specific Questions
- What pattern can reliably suppress pagination controls when the filtered collection contains zero items?
- Does Hugo provide a way to apply .Where directly to a slice before invoking .Paginate, or must one always work with PageCollections?
- When rendering a paginator inside a partial, how can the partial access the current page number without leaking the parent page’s paginator state?