h2o-php icon indicating copy to clipboard operation
h2o-php copied to clipboard

Feat: Implement iterating over explicit list.

Open jonathanverner opened this issue 11 years ago • 2 comments

When using h2o I found it useful to be able to use the {% for %} block to iterate over a list given explicitly in the template, e.g.:

{% for year in 2014, 2015, 2016, 2017 %}
    See <a href={{year}}.html>here</a>
{% endfor %}

This commit implements this feature by allowing the for to iterate over a comma-separated list of values.

jonathanverner avatar May 19 '14 22:05 jonathanverner

I am not sure about comma list. How does similar templates handle this? (django, jinja, liquid)

speedmax avatar May 21 '14 11:05 speedmax

It seems that django and liquid do not have this feature, jinja has the list in square brackets, values separated by commas, e.g.:

{% for  month in ['Jan','Feb','Mar'] %}
    {{ month }}
{% endfor %}

A little bit more to type, but very reasonable. Also, if string literals were to be supported, the implementation would have to make sure to ignore commas in the literals (a bit more work than just calling the split function)

jonathanverner avatar May 21 '14 17:05 jonathanverner