PRO: Pagination by twig – several feeds, many pages

This page demonstrates how you can paginate data. The data comes in a several feeds (see here for data in one feeds)

Create a new JCI-Template for that:

  • Name of Template: paginate
  • URL:
{% set page = 0 %}{% if urlparam.no %}{% set page = urlparam.no-1 %}{% endif %}
https://api.json-content-importer.com/extra/api/pagination/?page={{page}}
  • urlparam4twig: no
  • twig template:
{% set noonpage = 10 %}
 {% set noofpages = (totalno/noonpage) | round(0, 'ceil') %}
no of found dataitems: {{totalno}}, show on {{noofpages}} pages, each with {{noonpage }} items
<br>
{% set page = 1 %}{% if urlparam.no %}{% set page = urlparam.no %}{% endif %}
{% for i in 1..noofpages %} 
{% if i==page %} 
//<b>this is page: </b> {{page }} //
{% else %} 
<a href=?no={{i}}>{{i}}</a>
{% endif %} 
{% endfor %}
{% set currentpage = 1 %}
{% if urlparam.no %}{% set currentpage = page %}{% endif %}
<br>{% set start = noonpage * (currentpage-1) +1 %}
{% set end = start + noonpage -1 %} 
{% if start < 1 %} {% set start = 1 %} {% set end = noonpage %} {% endif %} 
{% if end > totalno %} {% set end = totalno %} {% endif %} 
show {{start}} to {{end}}
<br>
{% for k,v in items %} 
{{k}}: {{v}}<br>
{% endfor %} 

Example in action:

no of found dataitems: 87, show on 9 pages, each with 10 items
1 2 3 //this is page: 4 // 5 6 7 8 9
show 31 to 40
31: c16a5320fa475530d9583c34fd356ef5
32: 6364d3f0f495b6ab9dcf8d3b5c6e0b01
33: 182be0c5cdcd5072bb1864cdee4d3d6e
34: e369853df766fa44e1ed0ff613f563bd
35: 1c383cd30b7c298ab50293adfecb7b18
36: 19ca14e7ea6328a42e0eb13d585e4c22
37: a5bfc9e07964f8dddeb95fc584cd965d
38: a5771bce93e200c36f7cd9dfd0e5deaa
39: d67d8ab4f4c10bf22aa353e27879133c
40: d645920e395fedad7bbbed0eca3fe2e0