{
{# data #}
  "data": [
{% if items is defined %}
{% for item in items %}
{% include 'partials/data.json.twig' with {'item': item} only %}{% if not loop.last %},{% endif ~%}
{% endfor %}
{% else %}
{% include 'partials/data.json.twig' with {'item': page} only -%}
{% endif %}
  ]
{#- meta #}
{% block meta %}
{% if meta is not defined and page.paginator.pages is defined %}
{% set meta = {'totalPages': page.paginator.totalpages} %}
{% endif %}
{% if meta is defined %},
  "meta": {
{% for key, value in meta %}
    "{{ key }}": {{ value|json_encode() }}{% if not loop.last %},{% endif %}
{% endfor ~%}
  }
{%- endif %}
{% endblock meta %}
{# links #}
{% block links %}
{% if links is not defined and page.paginator.pages is defined %}
{% set links = {
  'self': url(page.paginator.links.self, {canonical: true, format: 'json'}),
  'first': url(page.paginator.links.first, {canonical: true, format: 'json'}),
  'last': url(page.paginator.links.last, {canonical: true, format: 'json'})
} %}
{% if page.paginator.links.prev is defined %}
{% set links = links|merge({'prev': url(page.paginator.links.prev, {canonical: true, format: 'json'})}) %}
{% endif %}
{% if page.paginator.links.next is defined %}
{% set links = links|merge({'next': url(page.paginator.links.next, {canonical: true, format: 'json'})}) %}
{% endif %}
{% endif %}
{% if links is defined %},
  "links": {
    "self": "{{ links.self }}",
    "first": "{{ links.first }}",
{% if links.prev is defined %}
    "prev": "{{ links.prev }}",
{% endif %}
{% if links.next is defined %}
    "next": "{{ links.next }}",
{% endif %}
    "last": "{{ links.last }}"
  }
{%- endif %}
{% endblock links ~%}
}