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 5 6 //this is page: 7 // 8 9
show 61 to 70
61: 7f39f8317fbdb1988ef4c628eba02591
62: 44f683a84163b3523afe57c2e008bc8c
63: 03afdbd66e7929b125f8597834fa83a4
64: ea5d2f1c4608232e07d3aa3d998e5135
65: fc490ca45c00b1249bbe3554a4fdf6fb
66: 3295c76acbf4caaed33c36b1b5fc2cb1
67: 735b90b4568125ed6c3f678819b6e058
68: a3f390d88e4c41f2747bfa2f1b5f87db
69: 14bfa6bb14875e45bba028a21ed38046
70: 7cbbc409ec990f19c78c75bd1e06f215