pongo2 icon indicating copy to clipboard operation
pongo2 copied to clipboard

for loop over array

Open chhetripradeep opened this issue 6 years ago • 3 comments

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.

chhetripradeep avatar Oct 08 '19 17:10 chhetripradeep

This is not yet supported.

flosch avatar Jun 24 '22 17:06 flosch

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

jjkavalam avatar Feb 08 '23 03:02 jjkavalam

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?

randree avatar Oct 16 '23 09:10 randree