Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

[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.



14.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.