We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Simple WHILE

Hi all,

i'm not able to realize a simple for N times loop in VOLT. Has far as i can see there is no WHILE statement and FOR works only with arrays.

Currently i'm using array_fill from the controller to pass an array of N NULL elements to the template to iterate over it but i downvote for this approach. I've also tried something like

{% FOR i in 5 %}

but PHP, obviously, reported: PHP Warning: Invalid argument supplied for foreach()



8.1k

See define of foreach in PHP :)



20.4k

I suppose to know what foreach means. VOLT FOR statement is equal to PHP FOREACH. But how to have a simple loop in VOLT? Ex: Print 5 times the letter 'a' in VOLT.



1.2k
Accepted
answer

you mean like this ? {% for a in 0..10 %} {{ a }} {% endfor %}



20.4k

thanks linbob! This is exactly what i meant! Thanks very much!

In the documentation the only reference for this is in Operators=>Range. A clear example of the usage may help readers to find out this feature. Regards