If / Else / ElseIf Statements
As of March 2017, Branch Code is deprecated and no longer developed. Use the Twig syntax instead.
The basic construct of an if statement includes the following format.
{if} {/if}
The "{if}" part includes the actual logic for the if statement.
The "{/if}" is the closing part of the if statement.
You can also do {else} to handle an alternate logic path or do {elseif} to test another if test. Below is some basic examples.
{if #var length > 2}
<p>#var has a string length greater than 2</p>
{else}
<p>#var is too small</p>
{/if}
{if #var contains "hello"}
<p>Hello world!</p>
{elseif #var contains "boo"}
<p>Boo!</p>
{else}
<p>Goodbye</p>
{/if}
Arithmetic-Operators
Operator | Description |
---|---|
% mod |
Modulus
Examples |
* |
Multiplication
Examples |
+ |
Addition
Examples |
- |
Subtraction
Examples |
/ |
Division
Examples |
Comparison-Operators
Logical-Operators
Operator | Description |
---|---|
! not isNot |
Not
Examples |
&& and |
And ('and' has lower precedence)
Examples |
|| or |
Or ('or' has lower precedence)
Examples |
Statement-Parts
Operator | Description |
---|---|
contains |
Checks to see if the variable contains a value.
If the variable is an array then it looks to see if the value exists in the array (note that it checks array values not array keys).
If the variable is a string then it checks to see if the value matches the variable or if the value is a substring of the variable.
Examples |
containsKey |
Checks to see if the array contains a specific array key. Typically the value to test is a variable containing a string and typically the array to test in is a variable holding an array. Note that this checks array keys values not array values. Examples |
count |
This is used to check to see if an array has a certain size. Examples |
dateIsAfter |
Checks to see if one date occurs after another date. This literally tests to see if one date is at least 1 second after another date. The variable(s) being tested should either contain a UNIX timestamp or be a date string like: Examples
|
dateIsBefore |
Checks to see if one date occurs before another date. This literally tests to see if one date is at least 1 second before another date. The variable(s) being tested should either contain a UNIX timestamp or be a date string like: Examples
|
dayIsAfter |
Checks to see if one date is the next day or later compared to another date. The variable(s) being tested should either contain a UNIX timestamp or be a date string like: Examples
|
dayIsBefore |
Checks to see if one date is the previous day or earlier compared to another date. The variable(s) being tested should either contain a UNIX timestamp or be a date string like: Examples
|
doesNotExist |
Checks to see if a variable either does not exists or does not have a value. Examples |
endsWith |
Checks to see if the string ends with a certain value. The length of the value to test does not matter. Examples |
exists exist |
Checks to see if a variable is a string with a value, a number or an array with one or more values. Examples |
hourIsAfter |
Checks to see if one date is the next hour or later compared to another date. The variable(s) being tested should either contain a UNIX timestamp or be a date string like: Examples
|
hourIsBefore |
Checks to see if one date is the previous hour or earlier compared to another date. The variable(s) being tested should either contain a UNIX timestamp or be a date string like: Examples
|
isArray |
Checks to see if the variable is an array
Examples |
isBool |
Checks to see if the variable is a boolean (true or false) value.
Examples |
isEven |
Checks to see if the variable value is an even number. Examples |
isFloat isDouble |
Checks to see if the type of the variable is float (a real number). Examples |
isInArray |
Checks to see if the a value exists in an array. (Also see isNotInArray) Typically the value to test is a variable containing a string and typically the array to test in is a variable holding an array. Note that this checks array values not array keys. Examples |
isInt isInteger isLong |
Checks to see if the type of the variable is an integer. Examples |
isNotInArray |
Checks to see if the a value does not exist in an array. (Also see isInArray) Typically the value to test is a variable containing a string and typically the array to test in is a variable holding an array. Note that this checks array values not array keys. Examples |
isNull |
Checks to see if the variable is NULL. Examples |
isNumeric |
Checks to see if the variable is numeric. Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. Hexadecimal notation (0xFF) is allowed too but only without sign, decimal and exponential part. Examples |
isOdd |
Checks to see if the variable value is an odd number. Examples |
isString |
Checks to see if the type of the variable is a string. Examples |
length |
This is used to check to see if a string is a certain length. Examples |
minuteIsAfter |
Checks to see if one date is the next minute or later compared to another date. The variable(s) being tested should either contain a UNIX timestamp or be a date string like: Examples
|
minuteIsBefore |
Checks to see if one date is the previous minute or earlier compared to another date. The variable(s) being tested should either contain a UNIX timestamp or be a date string like: Examples
|
monthIsAfter |
Checks to see if one date is the next month or later compared to another date. The variable(s) being tested should either contain a UNIX timestamp or be a date string like: Examples
|
monthIsBefore |
Checks to see if one date is the previous month or earlier compared to another date. The variable(s) being tested should either contain a UNIX timestamp or be a date string like: Examples
|
startsWith |
Checks to see if the string starts with a certain value. The length of the value to test does not matter. Examples |
yearIsAfter |
Checks to see if one date is the next year or later compared to another date. The variable(s) being tested should either contain a UNIX timestamp or be a date string like: Examples
|
yearIsBefore |
Checks to see if one date is the previous year or earlier compared to another date. The variable(s) being tested should either contain a UNIX timestamp or be a date string like: Examples
|