I am new to jinja and need some help with doing the following:
main.tpl has the following content:
{%- with PREFIX = "test." %}
{%- set TEST_VARIABLE = "false" %}
{%- include "child1.tpl" %}
{%- endwith %}
How can I use TEST_VARIABLE in child1.tpl such that when it is false, I set a property like this to false else true:
{%- if {TEST_VARIABLE} == false %}
PROPERTY1=false
{%- else %}
PROPERTY1=true
{%- endif %}
I get and error saying unexpected '{' in field name.
There are two errors in your
child1.tplfile. First, you are using invalid syntax to refer to a variable in yourifstatement. Second, you are comparing a string ("false") with a boolean variable (false). This won't do what you want. Fixing both of these issues gives you:Using this and your
main.tplworks without errors. Changingset TEST_VARIABLE = "false"toset TEST_VARIABLE = "something else"changes the final template output as expected.With your original
main.tplandchild1.tplas above:If I modify
main.tplto look like:Then I get: