With Jinja2, is there any way to identify the variable used in PARSER
before doing the for
loop?
Context = """
{% macro LopyLoop(PARSER) %}
{% for items in PARSER -%}
{{ items }}{% if not loop.last %},{% endif %}
{%- endfor %}
{% endmacro %}
{% set Mainlist = ['ABC','XYZ'] %}
{{ LopyLoop(Mainlist) }}
{{ LopyLoop(Mainlist[0]) }}
)
"""
Output = Template(Context)
print Output.render()
The above is valid is valid when using ["ABC","XYZ"]
but is not when using a string Mainlist[0]
I can't find the a way to solve this one.