Pagerfanta Twig

Twig integration and pre-built pagination-control templates for Pagerfanta

Library
Composer
vv4.8.0
32stars
Custom / Unknown

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
24/100Needs Attention
Development Activity4
Maintenance0
Community20
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
71/100Good
Architecture65
Code Quality70
Innovation55
Learning Curve92

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/PagerfantaRuntime pair registering a pagerfanta() Twig function
  • A TwigView renderer 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search