Allow dynamic collection pagination#781
Merged
Merged
Conversation
..................................................✓......................... ............................................. ──────────────────────────────────────────────────────────────────── Laravel FIXED ................................... 121 files, 1 style issue fixed ✓ src/Handlers/PaginatedPageHandler.php unary_operator_spaces, not_operator… )
damiani
approved these changes
May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR allows paginating custom, dynamic collections. Fixes #273, although it does not use the config approach suggested there.
Issue
To paginate a collection, Jigsaw requires a source Blade template with a pagination key in its YAML front matter pointing at the target collection.
This breaks for dynamic collections, those generated at build time, like posts grouped by tag. You can build them in
afterCollections, but each still needs a source file (source/tags/php.blade.php,source/tags/laravel.blade.php,source/tags/javascript.blade.php, etc.) created before you even know which tags exist.Solution
With this PR, you can register paginated collections on the fly thanks to
paginateCollection. The typical use case is tag/category pages. Let's say you want paginated pages of all your posts with certain tag ("PHP", "JavaScript", etc). Inbootstrap.php:That generates
build/tags/php/index.html,build/tags/php/2/index.html, etc. Same pagination object ($pagination->items,$pagination->next, etc.) as the file-based approach, just driven from code instead of a source file.What changed
Jigsaw::paginateCollection()API: registers a paginated page definition (path, collection, template, perPage, optional variables) for deferred rendering after collections are builtPaginatedPageHandler::handleDefinition(): new method that renders paginated pages from a template view name instead of a source fileCollectionPaginator::paginate(): refactored to acceptrelativePathandfilenameas separate strings instead of a$fileobject, decoupling it from the filesystemOutputFile:InputFileis now nullable to support pages that have no backing source fileSiteBuilder::generatePaginatedPages(): new private method that processes pending page definitions and merges them into the build outputViewRenderer::renderView(): new method to render a view by name (usingview()->make()) rather than by file pathHow to test
bootstrap.php, hook intoafterCollections. Use teh snippet presented above._layouts/tag.blade.phpthat uses$pagination../vendor/bin/jigsaw buildand verifybuild/tags/php/index.htmland paginated sub-pages are generated correctly../vendor/bin/phpunit tests/DynamicCollectionPaginationTest.php, all 5 tests should pass.