Operators of Condition


These operators impose condition on your template output, it depends on the result of logical expression placed to the right of the operator’s body.

CT++ 1.7.5 defines two operators of condition: <TMPL_if LOGICAL_EXPR> and <TMPL_unless LOGICAL_EXPR>.

Both operators evaluates logical expression to the result and according to it executes or not the further instructions. You can also use variables (local and global) and user defined functions inside of the operator’s body.


<TMPL_if LOGICAL_EXPR>
    Some instructions if result has true value.
<TMPL_else>
    Some instructions if result has false value.
</TMPL_if>

<TMPL_unless LOGICAL_EXPR>
    Some instructions if result has false value.
<TMPL_else>
    Some instructions if result has true value.
</TMPL_unless>


The branch of <TMPL_else> is not firmly binds, it means that the following notification is allowed: <TMPL_if LOGICAL_EXPR> Some instructions </TMPL_if>. Thus the operator <TMPL_unless differs from the operator <TMPL_if in the executing some instructions if the evaluated value is false. Example 2.1:

Template: "Hello, <b><TMPL_var username></b>!<TMPL_else>Wrong user name!</TMPL_if>
Parameter: username => "Vasya"
Output: "Hello, Vasya!"


Example 2.2:

Template: "<TMPL_if username>Hello, <b><TMPL_var username>!<TMPL_else>Wrong user name!</TMPL_if>
Parameter: not defined.
Output: "Wrong user name!"


The sense is different for the second operator:

Example 2.3:

Template: "<TMPL_unless username>Hello, <b><TMPL_var username></b>!<TMPL_else>Wrong user name!</TMPL_unless>
Parameter: "Vasya"
Output: "Wrong user name!"



Copyright © 2003 - 2005 CTPP Dev. Team | http://reki.ru/products/ctpp