paginate Tag
The paginate
tag provides pagination context variables so you can easily load the next or previous page of data.
Within the paginate
tag, the variables paginate.next
, paginate.current
, and paginate.previous
(if the current page is > 1) will be set to the correlating URLs based on the current page query param value.
The query param that represents the current page is determined by the name of the resource in the schema and page JSON with _page
as the suffix.
Example
Page JSON
{
"categories": {
"pagination": {
"page_size": 50
}
}
}
Template
// Current URL: mysite.com/shop/all?categories_page=2
{% block body %}
{{ parent() }}
{% paginate categories %}
// mysite.com/shop/all?categories_page=2
<h2>Current: {{ paginate.current }}</h2>
// mysite.com/shop/all?categories_page=3
<h2>Next: {{ paginate.next }}</h2>
// mysite.com/shop/all?categories_page=1
<h2>Previous: {{ paginate.previous }}</h2>
{% for category in categories %}
<li>{{ category.name }}</li>
{% for item in category.items %}
<h1>{{ item.name }}</h1>
{% endfor %}
{% endfor %}
{% endpaginate %}
{% endblock %}