10-19-2021 09:06 PM - edited 10-20-2021 03:33 PM
When setting a variable that I want to use else where in a Jinja template, I find it does not seem to work.
For example, the simple script below compares the building name provided in a variable.
{% set building = 'YAB' %}
Building is {{ building }}
{% if 'YAB' == "{{ building }}" %}
Right Building
{% else %}
Wrong Building
{% endif %}
The answer is always Wrong Building, it is as though the if statement cannot read variables, even though my testing statement at the beginning produces the Right building name.
Is there something I am missing regarding using variables?
Solved! Go to Solution.
10-20-2021 06:34 PM
I worked out the problem (other than being a newbie), the reason this isn't working is because of the brackets I had on the variable.
{% set building = 'YAB' %}
Building is {{ building }}
{% if 'YAB' == building %}
Right Building
{% else %}
Wrong Building
{% endif %}
10-20-2021 06:34 PM
I worked out the problem (other than being a newbie), the reason this isn't working is because of the brackets I had on the variable.
{% set building = 'YAB' %}
Building is {{ building }}
{% if 'YAB' == building %}
Right Building
{% else %}
Wrong Building
{% endif %}
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide