If you use Cheetah, please support the project and register by clicking here:


7.3 One-line #if

Syntax:

#if EXPR1 then EXPR2 else EXPR3#

The #if flow-control directive (section 9.4) has a one-line counterpart akin to Perl's and C's ?: operator. If EXPR1 is true, it evaluates EXPR2 and outputs the result (just like #echo EXPR2#). Otherwise it evaluates EXPR3 and outputs that result. This directive is short-circuiting, meaning the expression that isn't needed isn't evaluated.

You MUST include both 'then' and 'else'. If this doesn't work for you or you don't like the style use multi-line #if directives (section 9.4).

The trailing # is the normal end-of-directive character. As usual it may be omitted if there's nothing after the directive on the same line.

If you use Cheetah, please support the project and register by clicking here: