How to stop loop index from resetting inside for loop of a pagination?

40 views Asked by At

I'm trying to display a list of user's contacts with their count. For example: if user has 13 contact in his list, all 13 of them will be displayed, from 1 to 13, using a simple for loop in loop.index in jinja. so far, no problem. But after adding paginatoin, the loop.index keeps resetting in each page. for example, if per_page is 5, loop index will be 1 to 5 in page 1, again 1 to 5 in page 2, and again 1 to 3 in page 3.

I need it to be 1-5 in page 1, 6-10 in page 2, and 11-13 in page 3.

is there a way to achieve this?

Here is my template:

{% for item in pagination.items %}
        <p>
            {{ loop.index }}
            {{ item.name }}
            {{ item.number }}
        </p>
{% endfor %}

I tried defining a counter var myself. Couldn't make it work.

0

There are 0 answers