I have a variable page.stock which is set on the load as the string "3,4,5,6".
I want to loop through this variable. I tried:
{% for mysize in app.request.get(page.stock) %}
<input type="radio" id="{{mysize}}" name="size" value="{{mysize}}" >
<label for="{{mysize}}">{{mysize}}</label>
{% endfor %}
and I also tried:
{% for mysize in page.stock %}
<input type="radio" id="{{mysize}}" name="size" value="{{mysize}}" >
<label for="{{mysize}}">{{mysize}}</label>
{% endfor %}
Both with no luck. How do I iterate through the ,
delimited string?
You'll need to split the string into a list:
{% for mysize in page.stock|split(',') %}
<input type="radio" id="{{mysize}}" name="size" value="{{mysize}}" >
<label for="{{mysize}}">{{mysize}}</label>
{% endfor %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With