/symfony-ux-skills:ux-paginationfrom symfony-ux-skills
Paginates Doctrine queries, arrays, and API results with numbered links or cursors. Supports offset, lookahead, and signed cursor pagination with filter-preserving links.
Ships in symfony-ux-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
One lazy, request-aware API to paginate arrays, Doctrine ORM and DBAL queries, and custom data sources. It validates ?page= and ?cursor=, keeps the current filters in every link, and renders accessible <nav> markup with real links, served as plain HTML.
Since Symfony UX 3.5+. The package is experimental: its API may still change.
composer require symfony/ux-pagination
Until the Flex recipe is published, register Symfony\UX\Pagination\UXPaginationBundle::class => ['all' => true] in config/bundles.php. 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.
Optional stylesheet for the default theme:
{# AssetMapper #}
<link rel="stylesheet" href="{{ asset('@symfony/ux-pagination/style.min.css') }}">
With Encore: npm install @symfony/ux-pagination, then import '@symfony/ux-pagination/style.min.css';.
use Symfony\UX\Pagination\PaginatorInterface;
#[Route('/products', name: 'product_index')]
public function index(ProductRepository $repository, PaginatorInterface $paginator): Response
{
$products = $paginator->paginate($repository->createQueryBuilder('product'));
return $this->render('product/index.html.twig', ['products' => $products]);
}
{% for product in products %}
<article>{{ product.name }}</article>
{% else %}
<p>No product.</p>
{% endfor %}
{{ ux_pagination(products) }}
{# or, with TwigComponent: <twig:ux:pagination :pagination="products" /> #}
The page comes from the page route attribute, then the page query parameter, then defaults to 1. paginate(page: 3) bypasses the request. Query parameters (filters) are preserved in generated links by default.
| The screen needs... | Strategy | Builder |
|---|---|---|
| Exact total, numbered links | Offset | query($source) (or paginate($source)) |
| Only previous/next, no count query | Lookahead | query($source)->lookahead() |
| Stable traversal of a large or changing set | Cursor | cursor($source)->orderBy([...], 'DESC') |
// Offset with a sliding window of 5 pages
$products = $paginator->query($qb)->perPage(20)->sliding(size: 5)->paginate();
// Lookahead: fetches perPage + 1 rows, totals are null
$activity = $paginator->query($qb)->perPage(30)->lookahead()->paginate();
// Cursor: signed opaque tokens in ?cursor=, no count, no page numbers
$entries = $paginator
->cursor($repository->createQueryBuilder('entry')) // no orderBy() on the source
->orderBy(['createdAt', 'id'], 'DESC') // unique tie-breaker last
->perPage(50)
->paginate();
All three return iterable results; templates that only iterate and render ux_pagination() work with any of them. Deep offsets are rejected above max_offset (100,000 by default).
For sort order, tie-breakers and cursor invalidation, check the cursor pagination troubleshooting guide.
Builders are immutable; finish with ->paginate():
$products = $paginator
->query($repository->listQuery($category))
->perPage(12)
->throwOnOutOfRange() // count now, 404 past the last page
->excludeQueryParameters('debug') // drop a parameter from links
->fragment('results') // #results on every link
->paginate();
total(int|callable): provide the exact total (required for GROUP BY, HAVING, multiple roots).pageParameter('orders_page'): one parameter per list when a page shows several lists.route('name', [...]), path('/x'), queryParameters([...]), discardQueryString(): control link URLs.fromCallbacks(slice: fn (int $offset, int $limit) => ..., count: fn () => ...): paginate an API or search engine.# config/packages/ux_pagination.yaml
ux_pagination:
items_per_page: 20
max_offset: 100000
navigation:
mode: sliding # sliding | fixed | full
size: 5
theme: '@UXPagination/theme/default.html.twig'
paginators:
products: # autowire as PaginatorInterface $productsPaginator
items_per_page: 12
Named paginators inherit the root options. Inject them by argument name ($productsPaginator) or with #[Target('products')].
Built-in themes: @UXPagination/theme/default.html.twig, bootstrap.html.twig (Bootstrap 5), tailwind.html.twig. 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.
{{ ux_pagination(
products,
{class: 'product-pagination', 'aria-label': 'Product results'},
theme: '@UXPagination/theme/tailwind.html.twig',
show_info: false,
navigation_attributes: {class: 'controls'},
link_attributes: {class: 'link'},
) }}
With Tailwind, add @source "../../vendor/symfony/ux-pagination/templates"; to your CSS (Tailwind 4) or the vendor path to content (Tailwind 3).
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveProp;
use Symfony\UX\LiveComponent\DefaultActionTrait;
use Symfony\UX\Pagination\LiveComponent\ComponentWithPaginationTrait;
use Symfony\UX\Pagination\PaginationBuilder;
use Symfony\UX\Pagination\PaginatorInterface;
#[AsLiveComponent]
final class ProductList
{
use DefaultActionTrait;
use ComponentWithPaginationTrait;
#[LiveProp(writable: true, url: true, onUpdated: 'onQueryUpdated')]
public string $query = '';
public function __construct(
private readonly ProductRepository $products,
private readonly PaginatorInterface $paginator,
) {}
protected function createPagination(): PaginationBuilder
{
return $this->paginator->query($this->products->searchQuery($this->query));
}
public function onQueryUpdated(): void
{
$this->resetPage();
}
}
<div {{ attributes }}>
<input type="search" data-model="debounce(300)|query">
{% for product in this.pagination %}<article>{{ product.name }}</article>{% endfor %}
{{ ux_pagination(this.pagination, link_attributes: this.paginationLinkAttributes) }}
</div>
Numbered pagination only (offset or lookahead). Links keep a real href, so they keep working even before LiveComponent connects.
Ask what the screen promises. Offset only when users see a total or page numbers; lookahead when "next" is enough; cursor when rows move during browsing.
Every cursor order ends with a unique field. ['createdAt', 'id'], one direction for all fields, no ORDER BY on the source query.
The page size belongs to the application. There is no visitor-controlled per-page parameter; use items_per_page or perPage().
Links stay links. Turbo Frames, Turbo Drive and LiveComponent enhance them; without JavaScript, every link still works.
symfony/ux-pagination on Packagist.ux_pagination() in a <turbo-frame> to update only the results.ComponentWithPaginationTrait for reactive filters.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub smnandre/symfony-ux-skills --plugin symfony-ux-skills20 skills in this plugin
/live-componentSymfony UX LiveComponent: live search, live filters, dependent selects and form validation as users type. Use for reactive PHP and Twig components, #[AsLiveComponent], LiveProp, LiveAction, data-model, loading states, emit/listen, lazy rendering and LiveResponse downloads./stimulusSymfony UX Stimulus: JavaScript behavior for dropdowns, tabs, modals, clipboard buttons and third-party widgets. Use for StimulusBundle, data-controller, data-action, targets, values, outlets, lazy controllers and Twig stimulus_* helpers./symfony-uxSymfony UX: choose and combine packages for a Symfony frontend. Use when deciding between Stimulus, Turbo, TwigComponent and LiveComponent, or fitting several Symfony UX packages into the same feature. Prefer the dedicated skill for a task that fits one package.Other plugins' skills for the same job