Download the PHP package morozgrafix/paginator-twig-extension without Composer
On this page you can find all versions of the php package morozgrafix/paginator-twig-extension. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download morozgrafix/paginator-twig-extension
More information about morozgrafix/paginator-twig-extension
Files in morozgrafix/paginator-twig-extension
Package paginator-twig-extension
Short Description Twig extension to help generate simple paginations in Twig templates.
License MIT
Homepage https://github.com/morozgrafix/PaginatorTwigExtension
Informations about the package paginator-twig-extension
PaginatorTwigExtension
Twig extension to help generate simple paginations in Twig templates.
Introduction
This extension helps building pagination in Twig templates. It will return an array with all necessary information to quickly display pagination links. It doesn't generate any HTML and it's up to you how you'd like to display it. Example below shows one of the ways of generating pagination compatible with Bootstrap CSS framework.
Extension is called with following function and accepts following parameters:
Parameters in detail:
current_page
- current page visitor is onlast_page
- last page in data set (total number of pages)num_items
- number of items that will be displayed in a pagination strip. Note: minimum allowed value is 7 and if even number is passed it will be bumped to next odd number for symmetry.separator
(optional) - custom separator for numbers not visible in pagination strip. Default is set to...
Basic example:
Calling
will set paginator
twig variable to:
Installation
Using Composer:
Logic in Twig template
Following example is compatible with Bootstrap 4 CSS framework.
Result with optional Prev
/Next
:
Result without Prev
/Next
:
Additional Examples
Custom separator:
Result:
Even number of items was specified, it gets bumped to next odd number for display symmetry (10 -> 11):
Result:
P.S.
This is my first Twig extension and it was quickly developed while I was working on a bigger project that needed pagination. I'm sure there are some pitfalls and additional features that can be added. Feel free to open an issue or submit a PR with improvements. Thanks. 🙇