9.4 #if ... #else if ... #else ... #end if

Syntax:

#if EXPR
#else if EXPR
#elif EXPR
#else
#end if

The #if directive and its kin are used to display a portion of text conditionally. #if and #else if should be followed by a true/false expression, while #else should not. Any valid Python expression is allowed. As in Python, the expression is true unless it evaluates to 0, '', None, an empty list, or an empty dictionary. In deference to Python, #elif is accepted as a synonym for #else if.

Here are some examples:

#if $size >= 1500
It's big
#else if $size < 1500 and $size > 0 
It's small
#else
It's not there
#end if

#if $testItem($item)
The item $item.name is OK.
#end if

Here's an example that combines an #if tag with a #for tag.

#if $people
<table>
<tr>
<th>Name</th>
<th>Address</th>
<th>Phone</th>
</tr>
#for $p in $people
<tr>
<td>$p.name</td>
<td>$p.address</td>
<td>$p.phone</td>
</tr>
#end for
</table>
#else
<p> Sorry, the search did not find any people. </p>
#end if

See section 7.3 for the one-line #if directive, which is equivalent to Perl's and C's ?: operator.