Pagerfanta Twig
Twig integration and pre-built pagination-control templates for Pagerfanta
Repository Health
Technical Analysis
Pagerfanta Twig integrates the Pagerfanta pagination library with the Twig templating engine, exposing a pagerfanta() Twig function that renders pagination controls (page links, previous/next, ellipsis) for any Pagerfanta-paginated collection. It ships with a set of ready-made view templates styled for common CSS frameworks, so developers don’t need to hand-write pagination markup.
The package includes templates for Bootstrap 3 through 5, Tailwind CSS, Foundation 6, Semantic UI, and a framework-agnostic default, letting applications drop in pagination controls that already match their existing design system with a single Twig function call.
What You Get
- A
PagerfantaExtension/PagerfantaRuntimepair registering apagerfanta()Twig function - A
TwigViewrenderer that maps a Pagerfanta result set to a chosen template - Ready-made templates for Bootstrap 3, 4, 5, Tailwind CSS, Foundation 6, Semantic UI, and a plain default style
- Straightforward selection of a specific template per call, or a global default
Common Use Cases
- Rendering page-number navigation controls for a Doctrine or array-backed Pagerfanta collection in Twig templates
- Matching pagination UI to an existing Bootstrap or Tailwind design system without writing custom markup
- Symfony applications using Twig that need consistent pagination controls across multiple listing pages
- Quickly prototyping paginated listings with the framework-agnostic default template
Under The Hood
Architecture
The package follows Twig’s runtime-extension pattern: PagerfantaExtension registers the pagerfanta Twig function, delegating actual rendering to PagerfantaRuntime, which is lazily instantiated by Twig only when the function is called. TwigView implements Pagerfanta’s view-rendering contract, selecting and rendering one of the bundled .html.twig templates (passed the current Pagerfanta collection and route-generation callback) to produce the final pagination markup.
Tech Stack
PHP 8.1+ depending on twig/twig (2.x/3.x) and pagerfanta/core for the underlying pagination abstraction; templates are plain .html.twig files rather than compiled PHP, keeping styling changes accessible to front-end developers. Tests use PHPUnit, including an integration test that renders actual Twig output.
Code Quality
The codebase is small and cleanly separated by responsibility (Extension for Twig wiring, View for rendering logic, templates as pure markup), with an integration test (TwigViewIntegrationTest) verifying real template rendering rather than only unit-testing the PHP glue code.
API Design
Usage is a single Twig function call ({{ pagerfanta(pager) }}) with an optional template-name argument to switch styles, making adoption near-instant for anyone already using Pagerfanta and Twig together; the bundled multi-framework templates remove the need to write custom CSS-framework-specific markup.