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 //this is page: 2 // 3 4 5 6 7 8 9
show 11 to 20
11: 6512bd43d9caa6e02c990b0a82652dca
12: c20ad4d76fe97759aa27a0c99bff6710
13: c51ce410c124a10e0db5e4b97fc2af39
14: aab3238922bcc25a6f606eb525ffdc56
15: 9bf31c7ff062936a96d3c8bd1f8f2ff3
16: c74d97b01eae257e44aa9d5bade97baf
17: 70efdf2ec9b086079795c442636b55fb
18: 6f4922f45568161a8cdf4ad2299f6d23
19: 1f0e3dad99908345f7439f8ffabdffc4
20: 98f13708210194c475687be6106a3b84