Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Implement iterating over explicit list. #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jonathanverner
Copy link

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.

      {% for e in 1,2,3,4 %}{{ e }}{% endfor %} => 12345
@speedmax
Copy link
Owner

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

@jonathanverner
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants