Now that you know how variables work, it's time to examine the TAL"condition" attribute, which lets you add decision-making capabilitiesto your templates. In this section, I'll be examining conditionalexpressions and comparison operators, and demonstrating, with practicalexamples, how they can be used to craft more intelligent code.
Let's begin with a simple example:<span tal:define="global switch string:on"></span><span tal:condition="switch">You left the light switch on</span>In this case, the visibility of the second <span> depends on thepresence or absence of the "switch" variable. If the variable ispresent, the second <span> will be displayed; if not, it will remainhidden.
All this happens via the special TAL "condition" attribute, which,according to the TAL specification, is used to "...include a particularpart of a Template only under certain conditions, and omit itotherwise". This TAL attribute is thus analogous to the traditional "if"statement found in all programming languages, and it can come in veryhandy when you need to add control flow routines to your templates.
The expression provided to the "condition" attribute must be a validTALES expression, which evaluates to either true or false.