{*if logicalExpression}
Description
Defines a conditional section that evaluates if a javascript expression is true/false.
Templates can include conditional sections. Conditionals allow you to choose what to do when specific values, aka conditions, are met. The {*if logicalExpression} command that helps define a conditional section in a template. 'logicalExpression'' is any Javascript expression that evaluates to a true/false value.
For example, consider the following data:
{
employees: [
{firstname: 'Fred', lastname: 'Smith', state: 'MA'},
{firstname: 'Laura', lastname: 'Linneker', state: 'CA'},
{firstname: 'Junior', lastname: 'Programmer', state: 'MA'},
{firstname: 'Bill', lastname: 'Lindsey', state: 'NY'}
]
}When an employee's state is "MA" we would like to print the text "Employee is based in MA".
{employees}
Employee name:{firstname} {lastname}
<div>
{*if state=='MA'}
Employee is based in MA
{*endif}
</div><br>
{/employees}This will result in the following
Employee name:Fred Smith Employee is based in MA Employee name:Laura Linneker Employee name:Junior Programmer Employee is based in MA Employee name:Bill Lindsey
If you want to use more that one 'if' statement with a logical expression then use the {*elseif logicalExpression} command.