Reputation: 1535
I am new to the world of Python. I have this 'if statement'
in my jinja2 template:
{{context.disabled==True and "Yes" or "No"}}
I am not sure what this syntax is called, but it works like an if
.
php equivalent would be: echo $disabled ? "Yes" : "No"
This is always returning No
or False
even though context.disabled
is True
,
Why is it behaving like this? I cant see why it is doing this, am I doing it wrong?
Upvotes: 3
Views: 451
Reputation: 48357
Not sure about boolean expressions in jinja templates, but you can use conditions:
{% if context.disabled %} "Yes" {% else %} "No" {% endif %}
Upvotes: 4
Reputation: 39728
What you want is something like this:
value = "Yes" if context.disabled else "No"
Upvotes: 6