October CMS resources and help articles

Simple and to the point. Optimized by the community.

Customize the pagination markup

4
by OFFLINE, last modified on August 12th, 2019

Given you have a Paginator instance stored in a $results variable:

$this['results'] = YourModel::paginate(10);

You can output the default pagination markup using the | raw filter:

{{ results | raw }}

If you need to customize the markup of the pagination you'll have to generate it yourself:

{% if results.hasPages %}
    <ul class="pagination">
        <li>
            {% if results.currentPage > 1 %}
                <a href="{{ results.previousPageUrl }}" rel="prev">«</a>
            {% else %}
                <span class="disabled">«</span>
            {% endif %}
        </li>

        {% for page in range(1, results.lastPage) %}
            <li>
                <a href="{{ results.url(page) }}">{{ page }}</a>
            </li>
        {% endfor %}

        <li>
            {% if results.hasMorePages %}
                <a href="{{ results.nextPageUrl }}" rel="next">»</a>
            {% else %}
                <span class="disabled">»</span>
            {% endif %}
        </li>
    </ul>
{% endif %}

Discussion

2 comments

1
AuthenticPinguin
Post on June 9th, 2020 1:22 PM

Hi there! That helped me a lot! Thanks! Small side-question: any idea how to create a paginator like this:

<< 1, 2, 3 .... 8, 9, 20>>

In case one has a lot of pages (like me) ;)

0
arrcrown
Post on July 2nd, 2020 12:00 AM
We use cookies to measure the performance of this website. Do you want to accept these cookies?