Pagination

Links to the pages of a long list.

Navigation Added in v0.53.0 Updated

Default


{component pagination,
	current: (int) ($request->query('page') ?? 1),
	total: 12,
/}

The pager is made of buttons that are plain links to ?page=N, the number Page::paginate() already reads. total is the page count, which Page::pageCount() gives for the same query, and current is the page being shown. The current page is outlined and marked aria-current="page", and the previous and next buttons are disabled at the ends. Nothing renders for one page or fewer.

{var $current = (int) ($request->query('page') ?? 1)}

{foreach $page->paginate('sort=-created') as $post}
	...
{/foreach}

{component pagination,
	current: $current,
	total: $page->pageCount('sort=-created'),
/}

siblings sets how many numbers show on each side of the current one, and the first and last page always show. href changes the link pattern, with {page} replaced by the number, for a pager that sits under another route or keeps other query parameters.

To swap only the results, put attrs: ['hx-boost:inherited' => 'true', 'hx-target:inherited' => '#results', 'hx-sync:inherited' => 'this:replace', 'hx-indicator:inherited' => '#results'] on the nav. HTMX 4 passes an attribute on to the links inside only with the :inherited suffix. The results dim while they load, and a newer click cancels the request still loading. Without JavaScript the links are plain navigation.

For a list that grows instead, {component more, href: $page->url('', ['page' => $number + 1])} is a button that adds the next batch to the end of the results. It is a plain link to the next page, so without JavaScript it is ordinary pagination. block (default rows) names the page block that returns the batch, which holds the batch and the next button, or nothing after the last one. auto: true loads the next batch as the button scrolls into view.