Conditional blocks allow to output (to process) or not to output (not to process) some particular fragment of a template depending on various conditions. These conditions are applied to the values of special template variables (such as $GROUP_ID$). A conditional block is opened by the '<?if()?>' operator and closed by the '<?endif?>' operator. Several conditional blocks can be nested. Conditional operators have the following syntax:
<?if($VARNAME$)?>true_code<?else?>false_code<?endif?>
* $VARNAME$ - name of a special variable, the value of which will be compared with a condition.
* true_code – HTML code to be displayed if a specified condition is true (can be empty if only negative test is necessary).
* false_code – HTML code to be displayed if a specified condition is false (can be absent together with '<?else?>' operator if only positive test is necessary).
Some examples:
<?if($USER_LOGGED_IN$)?>Hello $USERNAME$<?endif?>
<?if(!$USER_LOGGED_IN$)?>You are just a GUEST<?endif?>
<?if($USER_LOGGED_IN$ and $USERNAME$='Andrew')?>Hello Andrew<?endif?>
<?if($MODULE_ID$='load' and $PAGE_ID$='category')?>Categories page<?else?>Other page<?endif?>
* = - full coincidence of the value with the operand (case sensitive string comparison);
* ! - mismatch of the value with the operand (negation of case sensitive string comparison);
* > - the value is numerically greater than the operand (numerical comparison of integer or fractional decimal numbers);
* < - the value is numerically less than the operand (numerical comparison of integer or fractional decimal numbers);
* % - integer remainder of the division of the value by the operand (see note **);
* & - bitwise "AND" between the value and the operand (see note **);
* && (and) – logical AND;
* || (or) – logical OR;
* substr($STRING$,pos,num) - getting of a substring of the string $STRING$, starting from the position pos, of the length num characters;
* strpos($STRING$,'substring') - getting of a position of the substring substring in the string $STRING$;
*The variable's value is considered to be false (not true) if it is empty or equal to '0' (i.e. '4', 'Hello', '00' or '0.0' are considered to be true).
** For the operations '%' and '&' an operand can be specified either as one number or as two numbers separated by 'equals' character ('='). In the first case the result of the corresponding operation will be tested against non-zero value, i.e. '%2' means 'remainder of the division by 2 is not equal to zero'.
Examples:
You <?if($USER_LOGGED_IN$)?>have logged in as "$USERNAME$"<?else?>haven’t authorized yourself<?endif?>.
It outputs (having substituted $USERNAME$ by its value) You have logged in as "$USERNAME$". if $USER_LOGGED_IN$ is true, otherwise You haven’t authorized yourself.
<?if($USERNAME$='Hacker' || $USERNAME$='bad_boy' || substr($USERNAME$,0,4)='anti')?>No way, $USERNAME$!!!<?endif?>
It outputs (having substituted $USERNAME$) by its value No way, $USERNAME$!!! if $USERNAME$ equals to 'Hacker' or 'bad_boy', or begins with 'anti'.
<?if($POSTS$>50)?>***<?else?><?if($POSTS$>10.0)?>**<?else?>*<?endif?><?endif?>
It outputs ' *** ', if $POSTS$ is greater than 50, ' ** ', if it is greater than 10 and less than or equal to 50, and ' * ', if it is less than or equal to 10.
<?if($NUMBER$%2=1)?>odd<?else?>even<?endif?>
It outputs whether the value of $NUMBER$ is even or odd.