How can I mimic this PHP functionality in twig? I need to increment a number by 5 for each iteration of a for loop. The PHP code below works as expected:
for($x=5; $x<=20; $x+=5)
{
echo $x,'<br>';
}
which outputs:
5 ,10 ,15 ,20 ,
However this code in twig does not work as expected.
{% for y in range(0, 20) %}
{{ y + 5 }} ,
{% endfor %}
Which outputs:
5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25
I have also tried setting the new value of y for each iteration however that does not work either…
{% for y in range(0, 20) %}
{{ y + 5 }} ,
{% set y = y + 5 %}
{% endfor %}
Try this