Currentpage

The variable currentpage helps you to paginate folders with more than 10 posts. It can contain two different values:

  • int : Whenever you have an url structure like /p/3 it will return the final number (3) as currentpage.
  • false : In all other cases.

You can check the code of the cyanine theme to understand how a pagination works:

{% if item.elementType == 'folder' and item.contains == 'pages' %}

{% set pagesize = 10 %}
{% set pages = ( item.folderContent|length / pagesize)|round(0, 'ceil') %}
{% set currentpage = currentpage ? currentpage : 1 %}
{% set currentposts = (currentpage - 1) * pagesize %}
<ul class="post list pa0">

    {% for element in item.folderContent|slice(currentposts, pagesize) %}

        {% set post = getPageMeta(settings, element) %}
        {% set date = element.order[0:4] ~ '-' ~ element.order[4:2] ~ '-' ~ element.order[6:2] %}

        <li class="post-entry">
            <header>
                <a class="link f-link underline-hover" href="{{ element.urlAbs }}"><h2 class="mt4 mb2">{{ post.meta.title }}</h2></a>
                <div class="mt3"><small><time datetime="{{date}}">{{ date | date("d.m.Y") }}</time> | {{ post.meta.author }}</small></div>
            </header>
            <p>{{ post.meta.description }}</p>
        </li>

    {% endfor %}

    {% if pages > 1 %}
        <hr class="mv4">
        <p>Page: 
            {% for i in 1 .. pages %}
                {% if i == currentpage %}
                    {{i}}
                {% else %}
                    <a class="page" href="{{ item.urlAbs }}/p/{{i}}">{{i}}</a>
                {% endif %}
            {% endfor %}
        </p>
    {% endif %}

</ul>

{% endif %}

© by Sebastian Schürmanns, 2017 - 2021. All Rights Reserved. Built with Typemill.