Attention
TYPO3 v11 has reached end-of-life as of October 31th 2024 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.
Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v11 here: TYPO3 ELTS.
Pagination
Note
Pagination via Fluid widgets was removed, see Breaking: #92529 - All Fluid widget functionality removed. Use the API documented here to implement your own pagination.
The TYPO3 Core provides an interface to implement the native pagination of lists like arrays or query results of Extbase.
The foundation of that new interface \TYPO3\
is that
it's type agnostic. It means, that it doesn't define the type of paginatable objects. It's up to the
concrete implementations to enable pagination for specific types. The interface only forces you to
reduce the incoming list of items to an iterable
sub set of items.
Along with that interface, an abstract paginator class \TYPO3\
is available that implements the base pagination logic for any kind of Countable
set of
items while it leaves the processing of items to the concrete paginator class.
Two concrete paginators are available:
- For type
array
:\TYPO3\
CMS\ Core\ Pagination\ Array Paginator - For type
\TYPO3\
:CMS\ Extbase\ Persistence\ Query Result Interface \TYPO3\
CMS\ Extbase\ Pagination\ Query Result Paginator
Code-Example for the Array
:
// use TYPO3\CMS\Core\Pagination\ArrayPaginator;
$itemsToBePaginated = ['apple', 'banana', 'strawberry', 'raspberry', 'pineapple'];
$itemsPerPage = 2;
$currentPageNumber = 3;
$paginator = new ArrayPaginator($itemsToBePaginated, $currentPageNumber, $itemsPerPage);
$paginator->getNumberOfPages(); // returns 3
$paginator->getCurrentPageNumber(); // returns 3, basically just returns the input value
$paginator->getKeyOfFirstPaginatedItem(); // returns 5
$paginator->getKeyOfLastPaginatedItem(); // returns 5
// use TYPO3\CMS\Core\Pagination\SimplePagination;
$pagination = new SimplePagination($paginator);
$pagination->getAllPageNumbers(); // returns [1, 2, 3]
$pagination->getPreviousPageNumber(); // returns 2
$pagination->getNextPageNumber(); // returns null
// …
Hint
You can also rely on the the third-party extension EXT:numbered_pagination. This extension also offeres predefined templates.