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 //this is page: 3 // 4 5 6 7 8 9
show 21 to 30
21: 3c59dc048e8850243be8079a5c74d079
22: b6d767d2f8ed5d21a44b0e5886680cb9
23: 37693cfc748049e45d87b8c7d8b9aacd
24: 1ff1de774005f8da13f42943881c655f
25: 8e296a067a37563370ded05f5a3bf3ec
26: 4e732ced3463d06de0ca9a15b6153677
27: 02e74f10e0327ad868d138f2b4fdd6f0
28: 33e75ff09dd601bbe69f351039152189
29: 6ea9ab1baa0efb9e19094440c317e21b
30: 34173cb38f07f89ddbebc2ac9128303f