This example introduces the notation used to perform simple logic calculations in the templates.
It explores how to call logic and boolean operators such as AND/OR within the template, which is most useful in Conditional Sections.
It is best to view the template and output images or files side-by-side to understand their functionality.
Logical OR
The OR operator, represented by a double pipe "||", can be used with 2 or more fields or expressions.
Example 1 :
{sampleValue1||sampleValue2}
The OR operator evaluates if either sampleValue1 or sampleValue2 is true.
When used in a conditional section, the conditional section is shown if either value is true.
Example 2 :
{sampleValue3=’red’||sampleValue4=’red’}
In the expressions sampleValue3=’red', sampleValue4=’red' the "=" operator tests the values of sampleValue3 and sampleValue4 and returns true or false.
Then the OR operator evaluates whether either of the expressions have returned true.
When used in a conditional section, the conditional section is shown if either value is true.
Logical AND
The AND operator, represented by a double ampersand "&&", can be used with 2 or more fields or expressions.
Example 1 :
{sampleValue1&&sampleValue2}
The AND operator evaluates if both sampleValue1 and sampleValue2 are true.
When used in a conditional section, the conditional section is shown if both values are true.
Example 2 :
{sampleValue3=’red’&&sampleValue4=’red’}
In the expressions sampleValue3=’red’,sampleValue4=’red' the "=" operator tests the values of sampleValue3 and sampleValue4 and returns true or false.
Then the AND operator evaluates whether both expressions have returned true.
When used in a conditional section, the conditional section is shown if both values are true.
Logical NOT
The NOT operator, represented by an exclamation mark "!", can be used with one field or applied to an expression.
Example 1 :
!(sampleValue2)
The NOT operator inverses the value, i.e., if samplevelue1 is true, the expression !(sampleValue2)returns false.
When used in a conditional section, the conditional section is shown if value is false.
Example 2 :
!(sampleValue4=’red’)
In the expression sampleValue4=’red' the "=" evaluates the value of sampleValue4 and returns true or false.
Then NOT operator inverses the value.
When used in a conditional section, the conditional section is shown if value is false.
Combining logical expressions
(sampleValue3=’red’&&sampleValue4=’red’)||( sampleValue3=’green’&&sampleValue4=’green’)
In the expressions sampleValue3='red',sampleValue4='red',sampleValue3='green',sampleValue4='green' the "=" evaluates the values of sampleValue3 and sampleValue4 and returns true or false.
Then the AND operator evaluates whether both expressions within a set of parentheses have returned true. i.e., both sampleValue3=’red’ and sampleValue4=’red’ have returned true.
Finally, the OR operator is used to combine these two sets of expressions. i.e., either (sampleValue3=’red’&&sampleValue4=’red’) or ( sampleValue3=’green’&&sampleValue4=’green’) is true.
When used in a conditional section, the conditional section is shown if sampleValue3 and sampleValue4 are both 'red', or are both 'green'.