{"slug":"ux-pagination","title":"ux-pagination","summary":"Symfony UX Pagination: paginate Doctrine queries, arrays and API results with numbered links or cursors. Use for filtered lists, offset, lookahead and signed cursor pagination, PaginatorInterface, ux_pagination(), twig:ux:pagination, Twig themes and ComponentWithPaginationTrait.","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-12-02T16:48:39.215646Z","repo":{"url":"https://github.com/smnandre/symfony-ux-skills","stars":191,"forks":15,"license":"MIT","updatedAt":"2026-12-02T03:34:06Z"},"bodyHtml":"<hr>\n<h2>name: ux-pagination\ndescription: 'Symfony UX Pagination: paginate Doctrine queries, arrays and API results with numbered links or cursors. Use for filtered lists, offset, lookahead and signed cursor pagination, PaginatorInterface, ux_pagination(), twig:ux:pagination, Twig themes and ComponentWithPaginationTrait.'\nlicense: MIT\nmetadata:\nauthor: Simon André\nurl: <a href=\"https://smnandre.dev\">https://smnandre.dev</a></h2>\n<h1>UX Pagination</h1>\n<p>One lazy, request-aware API to paginate arrays, Doctrine ORM and DBAL queries, and custom data sources. It validates <code>?page=</code> and <code>?cursor=</code>, keeps the current filters in every link, and renders accessible <code>&lt;nav&gt;</code> markup with real links, served as plain HTML.</p>\n<p>Since Symfony UX 3.5+. The package is <strong>experimental</strong>: its API may still change.</p>\n<h2>Installation</h2>\n<pre><code>composer require symfony/ux-pagination\n</code></pre>\n<p>Until the Flex recipe is published, register <code>Symfony\\UX\\Pagination\\UXPaginationBundle::class =&gt; ['all' =&gt; true]</code> in <code>config/bundles.php</code>. Requires PHP 8.4+, Symfony 7.4 or 8.x, TwigBundle and Twig 3.10.3+. Doctrine ORM 3, DBAL 4.4+, TwigComponent and LiveComponent are optional.</p>\n<p>Optional stylesheet for the default theme:</p>\n<pre><code>{# AssetMapper #}\n&lt;link rel=\"stylesheet\" href=\"{{ asset('@symfony/ux-pagination/style.min.css') }}\"&gt;\n</code></pre>\n<p>With Encore: <code>npm install @symfony/ux-pagination</code>, then <code>import '@symfony/ux-pagination/style.min.css';</code>.</p>\n<h2>Quick Start</h2>\n<pre><code>use Symfony\\UX\\Pagination\\PaginatorInterface;\n\n#[Route('/products', name: 'product_index')]\npublic function index(ProductRepository $repository, PaginatorInterface $paginator): Response\n{\n    $products = $paginator-&gt;paginate($repository-&gt;createQueryBuilder('product'));\n\n    return $this-&gt;render('product/index.html.twig', ['products' =&gt; $products]);\n}\n</code></pre>\n<pre><code>{% for product in products %}\n    &lt;article&gt;{{ product.name }}&lt;/article&gt;\n{% else %}\n    &lt;p&gt;No product.&lt;/p&gt;\n{% endfor %}\n\n{{ ux_pagination(products) }}\n{# or, with TwigComponent: &lt;twig:ux:pagination :pagination=\"products\" /&gt; #}\n</code></pre>\n<p>The page comes from the <code>page</code> route attribute, then the <code>page</code> query parameter, then defaults to 1. <code>paginate(page: 3)</code> bypasses the request. Query parameters (filters) are preserved in generated links by default.</p>\n<h2>Choose a Strategy</h2>\n<table>\n<thead>\n<tr>\n<th>The screen needs...</th>\n<th>Strategy</th>\n<th>Builder</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Exact total, numbered links</td>\n<td>Offset</td>\n<td><code>query($source)</code> (or <code>paginate($source)</code>)</td>\n</tr>\n<tr>\n<td>Only previous/next, no count query</td>\n<td>Lookahead</td>\n<td><code>query($source)-&gt;lookahead()</code></td>\n</tr>\n<tr>\n<td>Stable traversal of a large or changing set</td>\n<td>Cursor</td>\n<td><code>cursor($source)-&gt;orderBy([...], 'DESC')</code></td>\n</tr>\n</tbody>\n</table>\n<pre><code>// Offset with a sliding window of 5 pages\n$products = $paginator-&gt;query($qb)-&gt;perPage(20)-&gt;sliding(size: 5)-&gt;paginate();\n\n// Lookahead: fetches perPage + 1 rows, totals are null\n$activity = $paginator-&gt;query($qb)-&gt;perPage(30)-&gt;lookahead()-&gt;paginate();\n\n// Cursor: signed opaque tokens in ?cursor=, no count, no page numbers\n$entries = $paginator\n    -&gt;cursor($repository-&gt;createQueryBuilder('entry'))   // no orderBy() on the source\n    -&gt;orderBy(['createdAt', 'id'], 'DESC')               // unique tie-breaker last\n    -&gt;perPage(50)\n    -&gt;paginate();\n</code></pre>\n<p>All three return iterable results; templates that only iterate and render <code>ux_pagination()</code> work with any of them. Deep offsets are rejected above <code>max_offset</code> (100,000 by default).</p>\n<p>For sort order, tie-breakers and cursor invalidation, check the <a href=\"references/gotchas.md#cursor-pagination\">cursor pagination troubleshooting guide</a>.</p>\n<h2>Builder Essentials</h2>\n<p>Builders are immutable; finish with <code>-&gt;paginate()</code>:</p>\n<pre><code>$products = $paginator\n    -&gt;query($repository-&gt;listQuery($category))\n    -&gt;perPage(12)\n    -&gt;throwOnOutOfRange()                  // count now, 404 past the last page\n    -&gt;excludeQueryParameters('debug')      // drop a parameter from links\n    -&gt;fragment('results')                  // #results on every link\n    -&gt;paginate();\n</code></pre>\n<ul>\n<li><code>total(int|callable)</code>: provide the exact total (required for <code>GROUP BY</code>, <code>HAVING</code>, multiple roots).</li>\n<li><code>pageParameter('orders_page')</code>: one parameter per list when a page shows several lists.</li>\n<li><code>route('name', [...])</code>, <code>path('/x')</code>, <code>queryParameters([...])</code>, <code>discardQueryString()</code>: control link URLs.</li>\n<li><code>fromCallbacks(slice: fn (int $offset, int $limit) =&gt; ..., count: fn () =&gt; ...)</code>: paginate an API or search engine.</li>\n</ul>\n<h2>Configuration</h2>\n<pre><code># config/packages/ux_pagination.yaml\nux_pagination:\n    items_per_page: 20\n    max_offset: 100000\n    navigation:\n        mode: sliding        # sliding | fixed | full\n        size: 5\n    theme: '@UXPagination/theme/default.html.twig'\n    paginators:\n        products:            # autowire as PaginatorInterface $productsPaginator\n            items_per_page: 12\n</code></pre>\n<p>Named paginators inherit the root options. Inject them by argument name (<code>$productsPaginator</code>) or with <code>#[Target('products')]</code>.</p>\n<h2>Rendering</h2>\n<p>Built-in themes: <code>@UXPagination/theme/default.html.twig</code>, <code>bootstrap.html.twig</code> (Bootstrap 5), <code>tailwind.html.twig</code>. They render numbered pages for offset results and only previous/next for lookahead and cursor results, and nothing at all when there is a single page.</p>\n<pre><code>{{ ux_pagination(\n    products,\n    {class: 'product-pagination', 'aria-label': 'Product results'},\n    theme: '@UXPagination/theme/tailwind.html.twig',\n    show_info: false,\n    navigation_attributes: {class: 'controls'},\n    link_attributes: {class: 'link'},\n) }}\n</code></pre>\n<p>With Tailwind, add <code>@source \"../../vendor/symfony/ux-pagination/templates\";</code> to your CSS (Tailwind 4) or the vendor path to <code>content</code> (Tailwind 3).</p>\n<h2>LiveComponent</h2>\n<pre><code>use Symfony\\UX\\LiveComponent\\Attribute\\AsLiveComponent;\nuse Symfony\\UX\\LiveComponent\\Attribute\\LiveProp;\nuse Symfony\\UX\\LiveComponent\\DefaultActionTrait;\nuse Symfony\\UX\\Pagination\\LiveComponent\\ComponentWithPaginationTrait;\nuse Symfony\\UX\\Pagination\\PaginationBuilder;\nuse Symfony\\UX\\Pagination\\PaginatorInterface;\n\n#[AsLiveComponent]\nfinal class ProductList\n{\n    use DefaultActionTrait;\n    use ComponentWithPaginationTrait;\n\n    #[LiveProp(writable: true, url: true, onUpdated: 'onQueryUpdated')]\n    public string $query = '';\n\n    public function __construct(\n        private readonly ProductRepository $products,\n        private readonly PaginatorInterface $paginator,\n    ) {}\n\n    protected function createPagination(): PaginationBuilder\n    {\n        return $this-&gt;paginator-&gt;query($this-&gt;products-&gt;searchQuery($this-&gt;query));\n    }\n\n    public function onQueryUpdated(): void\n    {\n        $this-&gt;resetPage();\n    }\n}\n</code></pre>\n<pre><code>&lt;div {{ attributes }}&gt;\n    &lt;input type=\"search\" data-model=\"debounce(300)|query\"&gt;\n    {% for product in this.pagination %}&lt;article&gt;{{ product.name }}&lt;/article&gt;{% endfor %}\n    {{ ux_pagination(this.pagination, link_attributes: this.paginationLinkAttributes) }}\n&lt;/div&gt;\n</code></pre>\n<p>Numbered pagination only (offset or lookahead). Links keep a real <code>href</code>, so they keep working even before LiveComponent connects.</p>\n<h2>Key Principles</h2>\n<p><strong>Ask what the screen promises.</strong> Offset only when users see a total or page numbers; lookahead when \"next\" is enough; cursor when rows move during browsing.</p>\n<p><strong>Every cursor order ends with a unique field.</strong> <code>['createdAt', 'id']</code>, one direction for all fields, no <code>ORDER BY</code> on the source query.</p>\n<p><strong>The page size belongs to the application.</strong> There is no visitor-controlled per-page parameter; use <code>items_per_page</code> or <code>perPage()</code>.</p>\n<p><strong>Links stay links.</strong> Turbo Frames, Turbo Drive and LiveComponent enhance them; without JavaScript, every link still works.</p>\n<h2>References</h2>\n<ul>\n<li><a href=\"https://ux.symfony.com/pagination\">Symfony UX package page</a> (<a href=\"https://ux.symfony.com/pagination.md\">Markdown summary</a>) · <a href=\"https://packagist.org/packages/symfony/ux-pagination\"><code>symfony/ux-pagination</code> on Packagist</a>.</li>\n<li>For strategies, application integration and deployment, see the <a href=\"https://symfony.com/bundles/ux-pagination\">Symfony UX Pagination documentation</a>.</li>\n<li><strong>API</strong> (builders, results, Twig function, themes, translations): <a href=\"references/api.md\">references/api.md</a></li>\n<li><strong>Patterns</strong> (filters, Turbo Frame, LiveComponent path routes, JSON APIs, external sources, testing): <a href=\"references/patterns.md\">references/patterns.md</a></li>\n<li><strong>Gotchas</strong> (HTTP errors, cursor rules, Doctrine counts, security): <a href=\"references/gotchas.md\">references/gotchas.md</a></li>\n</ul>\n<h3>Demos</h3>\n<ul>\n<li><a href=\"https://ux.symfony.com/pagination#pagination-tour\">Numbered pagination preview</a></li>\n<li><a href=\"https://ux.symfony.com/demos/pagination/themes\">Pagination Themes</a></li>\n<li><a href=\"https://ux.symfony.com/demos/pagination/cursor-pagination\">Cursor Pagination</a></li>\n<li><a href=\"https://ux.symfony.com/demos/pagination/live-pagination\">Live Pagination with reactive filters</a></li>\n</ul>\n<h2>See Also</h2>\n<ul>\n<li><strong>turbo</strong>: wrap the list and <code>ux_pagination()</code> in a <code>&lt;turbo-frame&gt;</code> to update only the results.</li>\n<li><strong>live-component</strong>: <code>ComponentWithPaginationTrait</code> for reactive filters.</li>\n</ul>\n","files":[{"path":"references/api.md","sizeBytes":12645,"isText":true},{"path":"references/gotchas.md","sizeBytes":6637,"isText":true},{"path":"references/patterns.md","sizeBytes":8973,"isText":true},{"path":"SKILL.md","sizeBytes":8799,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-12-02T16:49:29.002028Z","sha256":"27196A5E015F4E9AED1C5A9BEA45DE558BE996A248F54D52A91A8143C7CAF532","sizeBytes":15158},"review":null,"source":{"repositoryUrl":"https://github.com/smnandre/symfony-ux-skills","path":"skills/ux-pagination","license":"MIT","commit":"78c25ed0b79bcc21d7611002dc81d8b87c3316e2","subtreeSha":"F53E423AB2757B734287FC57414EECB072C7C6A0546C235BB7B0E5A31F94C85D","lastSyncedAt":"2026-12-02T16:48:36.132977Z"},"reviewedAt":"2026-12-02T16:51:14.921716Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/smnandre/symfony-ux-skills/tree/main/skills/ux-pagination"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install smnandre-symfony-ux-skills@llmmart"},{"target":"git","command":"git clone https://github.com/smnandre/symfony-ux-skills.git"}]}