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

[solved] Volt: Numeric "for" loop

Hi,

Is there a way in Volt to do a straight-up numeric "for" loop? It looks like the "for" construct in Volt is just for iterating through arrays, but I just want to iterate from 0 - 1.

Currently I do this:

<select data-stripe = "exp-year" class = "form-control">
    {% set counter = [0,1,2,3,4,5,6,7,8,9,10] %}
    {% for val in counter %}
        <option value = "{{ start_year + val }}">{{ start_year + val }}</option>
    {% endfor %}
</select>

But that doesn't seem very elegant.



21.5k
Accepted
answer
edited Oct '14

Something like this?

<select data-stripe = "exp-year" class = "form-control">
    {% for val in 0..10 %}
        <option value = "{{ start_year + val }}">{{ start_year + val }}</option>
    {% endfor %}
</select>

Yep, perfect. Thanks.