Concatenate lists in JINJA2

AFAIK you can't do it using native Jinja2 templating. You're better off creating a new combined iterable and passing that to your template, eg:

from itertools import chain

x = xrange(3)
y = xrange(3, 7)
z = chain(x, y) # pass this to your template
for i in z:
    print i

As per comments, you can explicitly convert the iterables into lists, and concatenate those:

{% for M in GRP1|list + GRP2|list %}

Concatenating lists like {{ GRP1 + GRP2 }} is available, in jinja2 versions 2.9.5 and above.

@Hsiao gave this answer originally as a comment

Tags:

Python

Jinja2