I would like to evaluate a variable within a dict object in Jinja. Is that possible?
JavaScript
x
8
1
{%- set obj_list = ['obj1', 'obj2'] %}
2
{%- set long_dict_set ={"key":"text text {{ obj_list }} text text"} %}
3
4
{{ long_dict_set }}
5
6
--Returns
7
>> {'key': 'text text {{ obj_list }} text text'}
8
In the example, {{ obj_list }}
is treated as text. Is there a syntax to evaluate this variable within?
Advertisement
Answer
You can use ~
to include variables within strings:
{%- set long_dict_set = {"key":"text text " ~ obj_list ~ " text text"} %}
Output:
{'key': "text text ['obj1', 'obj2'] text text"}