{*else}
Description
Code to execute when {*if logicalExpression} and {*elseif logicalExpression} conditions are not met.
Templates can include conditional sections. Conditionals allow you to choose what to do when specific values, aka conditions, are met. Conditional sections are defined using the following template commands:
- {*if logicalExpression}
- {*elseif logicalExpression}
- {*else}
- {*endif}
logicalExpression is any Javascript expression that evaluates to a true/false value. The logicalExpression can refer to data in the current 'row' of data. For example, consider the following data used in the '[Template Tester]':
{ 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" or "CA", we would like to print the text "Employee is based in MA" or "Employee is based in CA", respectively. If they are not in either state, the text "Employee is not based in MA or CA" should be printed instead. Using conditional template commands, we can check the value of state to determine which text should be printed, as shown in the template below:
{employees} Employee name: {firstname}{lastname}<br> <div> {*if state=='MA'} Employee is based in MA {*elseif state=='CA'} Employee is based in CA {*else} Employee is not based in MA or CA {*endif} </div><br> {/employees}
When the employees array data is processed, the template produces the result below:
Employee name: FredSmith Employee is based in MA Employee name: LauraLinneker Employee is based in CA Employee name: JuniorProgrammer Employee is based in MA Employee name: BillLindsey Employee is not based in MA or CA