Using Conditional Logic
Conditional logic is a means to conditionally include or exclude data in wrappers, descriptions and emails based on the value of a Field Variable. For example, conditional logic can be used to show the material of an item in a listing with a label (i.e. Material: Leather) and exclude the label if there is no value in the Field Variable.
When simply entering Material: [[Material]] into a description, the Material would be shown with a label. If the Material item specific was blank, the label would still show with no value after it.
With conditional logic, the output can be based on the value of the Field Variable. For example, adding the following: {{IF[[Material]]='','','Material: [[Material]]'}} would result in the label being entered only if the value of [[Material]] does not equal an empty string.
The syntax of conditional logic follows. The conditional statement is surrounded by {{ }} to identify it as conditional code.
{{IF[[Material]]='','','Material: [[Material]]'}}
Inside the braces, it is broken down into three parts, separated by commas. The first part IF[[Material]]='' is the conditional test. This is a statement that compares a field to a value. In this case, a check is performed to see if Material contains no text. The second part is the text that will output if the first part is true. In other words, if the Material variable is empty, then nothing will be placed into the output (signified by two single quotes with nothing in between them). The third part will be output when the first part is false. So if Material is not empty then Material: [[Material]] would be outputted which would further resolve to something like: Material: Leather
Conditional logic can be very powerful. The output of the 2nd and 3rd parts can be text or HTML. This will allow formatting to include different pictures based on the value of a variable as follows.
{{IF[[Material]]='Wood','<img source=http:\\www.mysite.com\wood.jpg />','<img source=http:\\www.mysite.com\steel.jpg />'}}
Creating a Conditional Test
The conditional test is made up of the IF statement, followed by an operator, followed by a value. Valid operators include =,<, >, and ~.
The ~ operator allows for wildcard searching using .Net regular expressions. For example, IF[[Material]]~'Wood\w*' will be true if material starts with "Wood". The asterisk as a wildcard is only the tip of the iceberg with what is allowed in regular expressions. Microsoft has complete documentation on using regular expressions.
Nested Conditional Logic
Conditional logic can also be nested. This means the action taken for the True or False conditions can itself be a conditional. Following is an example.
{{IF[[CoinCount]]='','','{{IF[[CoinCount]]='1','This listing is for one coin'','This listing is for multiple coins'}}'}}
- If CoinCount has no value, then no text will be outputted.
- If CoinCount has a value of 1, then "This listing is for one coin" will be outputted.
- If CoinCount is anything else, "This listing is for multiple coins" will be outputted.