Let's say that I have a variable
t = [(1, 'hello'), (2, 'world')]
What I want is to map this to a new list containing only the second element of the tuples, in a Jinja template:
{% set s = t | map(...) | list %}
The variable s
should be ['hello', 'world']
.
Is this possible in some way without using a custom filter?
Yep, it's the attribute
method:
{% set t = [(1, 'hello'), (2, 'world')] %}
{% set t1 = t|map(attribute=1)|list %}
{{ t1 }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With