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 %}
http://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 5 //this is page: 6 // 7 8 9
show 51 to 60
51: 2838023a778dfaecdc212708f721b788
52: 9a1158154dfa42caddbd0694a4e9bdc8
53: d82c8d1619ad8176d665453cfb2e55f0
54: a684eceee76fc522773286a895bc8436
55: b53b3a3d6ab90ce0268229151c9bde11
56: 9f61408e3afb633e50cdf1b20de6f466
57: 72b32a1f754ba1c09b3695e0cb6cde7f
58: 66f041e16a60928b05a7e228a89c3799
59: 093f65e080a295f8076b1c5722a46aa2
60: 072b030ba126b2f4b2374f342be9ed44