Reproduce “Switch” Functionality
Problem
You want to do something like this ExpressionEngine statement, using Twig:
{switch="<tr>|||"}
Solution
There are two possible solutions: divisible
, and cycle
.
{# Using `divisible` #}
{% if loop.index0 is divisible by(4) %}
<tr>
{% endif %}
{# Using `cycle` #}
{{ cycle(['<tr>','','',''],loop.index0)|raw }}
Discussion
Submitted by Sprocketeer on 1st February, 2017