1

I'm in need of help (again ;-) )... I'm trying to paginate the content of a matrix in a structure, but can't seem to get it done... This is the code I've got:

{% for inhoud in entry.getDescendants() %}
    {% if inhoud.type == 'segment' %}
        <section id="{{ inhoud.title|kebab }}" class="segment">
            <h2 class="section-h2">{{ inhoud.title }}</h2>
        </section>
    {% endif %}
    {% if inhoud.type == 'inhoud' %}
    {#{% paginate inhoud.trace.limit(10) as inhoud %}#}
        {% for inhoud in inhoud.trace %}
            {% include ["trace/" ~ inhoud.type, "trace/default" ] %}
        {% endfor %}
    {% endif %}
{% endfor %}

My pagination code is in comments since it doesn't work, but that's where I need the pagination. Is there anyone nice enough to want to help me figure this out? We've got a big matrix field (it's the route of certain products from farm 'till the shop, so lots of blocks in there), and I'd like to paginate the content of these 'segments', but we'll need those segments printed out because there's a navigation with anchorpoints on top of the site. Thanks!

2

Found the answer - I had to paginate the children of "inhoud". Works like a charm now :-)

    {% for inhoud in entry.getDescendants() %}
        {% if inhoud.type == 'segment' %}
            <section id="{{ inhoud.title|kebab }}" class="segment">
                <h2 class="section-h2">{{ inhoud.title }}</h2>
            </section>
        {% endif %}

    {% paginate inhoud.children.limit(10) as pageInfo, pageEntries %}
        {% for inhoud in pageEntries %}
           {% for inhoud in inhoud.trace %}
              {% include ["trace/" ~ inhoud.type, "trace/default" ] %}
            {% endfor %}
        {% endfor %}

     {% if pageInfo.totalPages>1 %}
            <div class="pagination" style="border-bottom: 0;">
                <div class="w-row">
                    <div class="pagination-left w-col w-col-6">
                        <div>pagina {{ pageInfo.currentPage }} van {{ pageInfo.totalPages }}</div>
                    </div>
                    <div class="pagination-right w-col w-col-6">
                        <a class="pag-link">
                            {% if pageInfo.prevUrl %}
                            <a class="pag-link" href="{{ pageInfo.prevUrl }}"></a>{% endif %}
                            {% for page, url in pageInfo.getPrevUrls(2) %}
                                <a href="{{ url }}" class="pag-link">{{ page }}</a>
                            {% endfor %}
                            <span>{{ pageInfo.currentPage }}</span>
                            {% for page, url in pageInfo.getNextUrls(2) %}
                                <a class="pag-link" href="{{ url }}">{{ page }}</a>
                            {% endfor %}
                            {% if pageInfo.nextUrl %}
                            <a class="pag-link" href="{{ pageInfo.nextUrl }}"></a>{% endif %}
                        </a>
                    </div>
                </div>
            </div>
        {% endif %}
    {% endfor %}

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.