flosch / pongo2

Django-syntax like template-engine for Go
https://www.schlachter.tech/pongo2
MIT License
2.88k stars 270 forks source link

for loop over array #220

Open chhetripradeep opened 5 years ago

chhetripradeep commented 5 years ago

I am trying to use pongo2 on this jinja2 template

{%- for table in ['foo', 'bar'] %}
DROP TABLE IF EXISTS {{table}};
{% endfor %}

but it fails pointing at [ character

Expected either a number, string, keyword or identifier.

Thank you for your help.

flosch commented 2 years ago

This is not yet supported.

jjkavalam commented 1 year ago

@flosch Is it possible to set the array to a variable first and use it. I got the idea from here: https://github.com/flosch/pongo2/blob/2533a7767364043df2d81686fe06e019234556b1/template_tests/set.tpl#L8

{% set new_var = ["hello", "val2"] %}
{% for item in new_var %}
...
{% endfor %}

However, this also seem to give the same error as reported here: Expected either a number, string, keyword or identifier.

randree commented 1 year ago

I can verify that problem. In my code I get an error and if I run a test on this repository everything works fine. Is there a problem with the test?