Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 527
4c74356b41 Avatar asked Aug 28 '17 09:08

4c74356b41


1 Answers

Nested {{..}} are not allowed.

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

like image 53
Konstantin Suvorov Avatar answered Sep 30 '22 21:09

Konstantin Suvorov