Search code examples
symfonypaginationtwigsymfony4pagerfanta

Is there an configuration to limit the numbers of page numbers in Pagerfanta pagination?


I have a pagination with Pagerfanta. I want to limit page numbers to 5, since on mobile version pagination is too large. I am using default view 'twitter_bootstrap_translated'.

{% if articles.haveToPaginate %}
   <div class="pagination-class">
      {{ pagerfanta(articles, 'twitter_bootstrap_translated', {routeName: 'search_result_paginated', routeParams: app.request.query.all}) }}
   </div>
{% endif %}

How I can limit the page numbers/links?

Currently: < Prev | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ... 101 | Next >

I need pagination like this: Currently: < Prev | 1 | 2 | 3 | ... 101 | Next >


Solution

  • Please have a look might be useful:

    <?php
    
    use Pagerfanta\View\TwitterBootstrapView;
    
    $view = new TwitterBootstrapView();
    $options = array('proximity' => 3);
    $html = $view->render($pagerfanta, $routeGenerator, $options);
    
    Options (default):
           proximity (3)
           prev_message (← Previous)
           prev_disabled_href ()
           next_message (Next →)
           next_disabled_href ()
           dots_message (…)
           dots_href ()
           css_container_class (pagination)
           css_prev_class (prev)
           css_next_class (next)
           css_disabled_class (disabled)
           css_dots_class (disabled)
           css_active_class (active)