Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Collection::routable() unexpected error

Started by Muut Archive 10 years ago · 9 replies · 374 views
10 years ago

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.

10 years ago
TWIG

{% 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 %}
---
10 years ago

Maybe you can try {% for p in collection if page.routable == true %}

10 years ago

Paul has the right of it but with a slight typo:

TWIG

{% for p in collection if p.routable == true %}
---
10 years ago

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.

10 years ago

Do I need to add a new {% endif %} too if I use an if in a for?

10 years ago

In that case no. It's a Twig construct. Loops an entry just if the condition is met.

10 years ago

I don't understand the explanation, but it works without endif. Thank you :)

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1366 9 years ago
Archive · by Muut Archive, 9 years ago
2 940 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2960 9 years ago
Archive · by Muut Archive, 9 years ago
3 1124 9 years ago