Pierre L
Pierre L

Reputation: 28451

How to evaluate a variable within a dict in jinja

I would like to evaluate a variable within a dict object in Jinja. Is that possible?

{%- set obj_list = ['obj1', 'obj2'] %}
{%- set long_dict_set ={"key":"text text {{ obj_list }} text text"} %}

{{ long_dict_set }}

--Returns
>> {'key': 'text text {{ obj_list }} text text'}

In the example, {{ obj_list }} is treated as text. Is there a syntax to evaluate this variable within?

Upvotes: 0

Views: 318

Answers (1)

saidalkharusi
saidalkharusi

Reputation: 76

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"}

Upvotes: 2

Related Questions