4c74356b41 4c74356b41 - 1 month ago 28
Python Question

Jinja: variable inside string inside if statement

I'm trying to create the following loop in jinja:

variable: >
[
{% for replaceme in list %}
{
'name': "{{ "string-{{replaceme}}" if replaceme == 'somevalue' else "string-something-{{replaceme}}" }}",
'sshKey': "{{ lookup(...) }}"
}
{% if not loop.last %},{% endif %}
{% endfor %}
]


but this doesn't work, any ideas? i tried different quotes, different combinations of curlies, etc.

Answer Source

Nested {{..}} are not allowed.

Try: {{ "string-"+replaceme if replaceme == 'somevalue' else "string-something"+replaceme }}