I have a Symfony 5 project where I use the KNP Paginator Bundle to paginate some results. I use the @KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig
template to render the pagination block. However, I would like it centered in my page.
I have looked at the template and I have seen this piece of code :
{% if pageCount > 1 %}
<nav>
{% set classAlign = (align is not defined) ? '' : align=='center' ? ' justify-content-center' : (align=='right' ? ' justify-content-end' : '') %}
{% set classSize = (size is not defined) ? '' : size=='large' ? ' pagination-lg' : (size=='small' ? ' pagination-sm' : '') %}
<ul class="pagination{{ classAlign }}{{ classSize }}">
{# ... #}
So I used a global Twig variable to center my pagination block by adding it to Twig configuration :
# config/packages/twig.yaml
twig:
# ...
globals:
align: 'center'
Still, I think this is not a proper way to do as it could cause conflicts with some other bundles or even my own code. I also think overriding the template to manually center the block is not a really proper way to do, and I have not found anything in the documentation to simply and elegantly do what I want to do. Still, I guess this align
Twig variable in the KNP Paginator template can be set some other way...
If anyone has a less disruptive way to center this block, it would be gladly welcome.