E
E
enjoy_1t2018-02-13 19:20:24
Twig
enjoy_1t, 2018-02-13 19:20:24

Twig question. How to display a multiple of three categories?

On the main page of my site on OpenCart CMS, the list of categories is displayed through
{% for category in categories %}
{% endfor %}
How can I make this for end at the largest multiple of 3?
So that, for example, if the site has 4 or 5 categories, it displays only three of them, and if there are 7 or 8, then 6, and so on by analogy. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zoozag, 2018-02-13
@zoozag

Try this
{% for category in categories %}
{% if loop.revindex > (loop.length % 3) %}
...
{% endif %}
{% endfor %}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question