Reputation: 196
I want to limit the pagination boxes going for ever. Say there is 100 events loaded -> 3 events are displayed/page; and such that the pagination boxes [1][2][3][4]....[40]
doesn't go on...
Upvotes: 0
Views: 714
Reputation: 1147
I guess that knp paginator does that for you but in case it does not You could try to modify any of the templates above to do something like this:
set a control variable
{% if pageCount > maxNumberOfBoxes %}
{% set breakpointAdded=true %}
{% endif %}
then find the loop which look like this
{% for page in pagesInRange %}
{% if page != current %}
<span class="page">
<a href="{{ path(route, query|merge({(pageParameterName): page})) }}">{{ page }}</a>
</span>
{% else %}
<span class="current">{{ page }}</span>
{% endif %}
{% endfor %}
and replace it for something like this(with your own logic of course)
{% for i in range(0,pageCount) %}
{% if i > xBreakpoint and i < yBreakpoint and breakpointAdded == false %}
<span class="dots">...</span>
{% set breakpointAdded = true %}
{% else %}
{% if page != current %}
<span class="page">
<a href="{{ path(route, query|merge({(pageParameterName): page})) }}">{{ page }}</a>
</span>
{% else %}
<span class="current">{{ page }}</span>
{% endif %}
{% endif %}
{% endfor %}
if anything of this works you could try to modify the getPaginationData function from SlidingPagination class.
what ever works for you.
Upvotes: 0
Reputation: 60
In config.yml
add this:
knp_paginator:
page_range: 5 # number of links showed in the pagination menu (e.g: you have 10 pages, a page_range of 3, on the 5th page you'll see links to page 4, 5, 6)
If you need change the sliding use any of these:
template:
pagination: '@KnpPaginator/Pagination/sliding.html.twig'
@KnpPaginator/Pagination/sliding.html.twig (by default)
@KnpPaginator/Pagination/twitter_bootstrap_v3_pagination.html.twig
@KnpPaginator/Pagination/twitter_bootstrap_pagination.html.twig
@KnpPaginator/Pagination/foundation_v5_pagination.html.twig
Upvotes: 1