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 4 //this is page: 5 // 6 7 8 9
show 41 to 50
41: 3416a75f4cea9109507cacd8e2f2aefc
42: a1d0c6e83f027327d8461063f4ac58a6
43: 17e62166fc8586dfa4d1bc0e1742c08b
44: f7177163c833dff4b38fc8d2872f1ec6
45: 6c8349cc7260ae62e3b1396831a8398f
46: d9d4f495e875a2e075a1a4a6e1b9770f
47: 67c6a1e7ce56d3d6fa748ab6d9af3fd7
48: 642e92efb79421734881b53e1e1b18b6
49: f457c545a9ded88f18ecee47145a72c0
50: c0c7c76d30bd3dcaefc96f40275bdc0a