2

I am trying to split entry into multiple pages.

In accordance with the docs, I am using this code on single-entry template:

{{ entry.body.getPage(1) }}

{% if entry.body.getTotalPages() > 1 %}
  <a href="{{ entry.url }}">Continue reading…</a>
{% endif %}

However {{ entry.url }} is always pointing to the same page that I'm on (base entry URL) without any pagination number, so I never get to second page. I have checked that {{entry.body.getTotalPages()}} returns 2, so the pagebreak plugin is working.

What am I missing here?

Answer:

Here's the working code that I got with Brad Bell's help:

{% set currentPage = 1 %}
{% if craft.request.getParam('page') is not empty %}
    {% set currentPage = craft.request.getParam('page') %}
{% endif %}

{{ entry.body.getPage(currentPage) }}

{% if entry.body.getTotalPages() > 1 %}
    {% set totalPages = entry.body.getTotalPages() %}

    {% for i in 1..totalPages %}
    <a href="{{ url(entry.url, {page: i}) }}">go to page: {{ i }}</a>
    {% endfor %}
{% endif %}
2

The example is the docs you're referring to will simple output the first "page" of the Rich Text field and if there are more pages show a "Continue Reading" link that loads the full entry.

For the functionality you're looking for you'd have to do something like this (completely untested):

{% set totalPages = entry.body.getTotalPages() %}

{% for i in 1..totalPages %}
    <a href="{{ url(entry.url, {page: i}) }}">{{ i }}</a>
{% endfor %}

Then your template would grab the page from the querystring and display it using entry.body.getPage(page).

1
  • Thank you! Now I got it working. Clearly the docs are missing this part. Jan 12 '16 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.