Why doesn't my condition logic work as expected in Jinja2/CherryPy?

Andrew Kloos picture Andrew Kloos · Dec 8, 2011 · Viewed 57.1k times · Source
{% if bCat2 == True %}
    <div>True</div>
{% else %}
    <div>False</div>

Returns <div>False</div> even when bCat2 is True. Thanks, Andrew

Answer

Evgeni Nabokov picture Evgeni Nabokov · Dec 20, 2011

This part of documentation can help you:

The special constants true, false and none are indeed lowercase. Because that caused confusion in the past, when writing True expands to an undefined variable that is considered false, all three of them can be written in title case too (True, False, and None). However for consistency (all Jinja identifiers are lowercase) you should use the lowercase versions.

Source: http://jinja.pocoo.org/docs/templates/

Try that code:

{% if bCat2 == true %}
<div>True</div>
{% else %}
<div>False</div>
{% endif %}