I’m trying to make a list of things in 4-column rows, 16 per page. The code below splits pages every 16 entries, including skipped ones. I would like to prevent counting invisible pages. I found Collection::routable() in the documentation but using {% set collection = collection::routable() %} results in an error message.
{% set collection = page.collection() %}
{% set colcount = 0 %}
{% block content %}
<div class="container">
{% for p in collection %}
{% if colcount == 0 %}
<div class="row">
{% endif %}
{% if (p.header.visible is not defined or p.header.visible) %}
{% set colcount = colcount + 1 %}
{% include 'partials/game_preview.html.twig' with {'page': p, 'parent': page} %}
{% endif %}
{% if colcount == 4 %}
</div>
{% set colcount = 0 %}
{% endif %}
{% endfor %}
</div>
{% endblock %}
---
Bump
Help?
Maybe you can try {% for p in collection if page.routable == true %}
Paul has the right of it but with a slight typo:
{% for p in collection if p.routable == true %}
---
Thank you. I am doing everything blind by just relying on the documentation and have no idea how to use PHP so all these methods, objects and syntax is highly confusing for me.
Do I need to add a new {% endif %} too if I use an if in a for?
In that case no. It’s a Twig construct. Loops an entry just if the condition is met.
I don’t understand the explanation, but it works without endif. Thank you