cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1538
Views
5
Helpful
1
Replies

Using Jinja variables in the Template Editor

CjD2018
Level 1
Level 1

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?

 

 

1 Accepted Solution

Accepted Solutions

CjD2018
Level 1
Level 1

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

View solution in original post

1 Reply 1

CjD2018
Level 1
Level 1

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