Client Side Template

{*if <defined<var 1,var 2>>}...{*endif}

Description

Executes a string or some data if a variable in the data set is defined.

This command simplifies the following much more cumbersome expression:

{*if typeof variableName1 != 'undefined' && typeof variableName2 != 'undefined'}
...
{*endif}

Example 

For example, say you have this set of JSON 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'}
    ]
}

Define the following template. Here the 'state'' field is defined in a conditional {*if logicalExpression} command. Because it is defined {*if <defined<state>>} {*endif} can then be used to add a string.

{employees}
    Employee name:{firstname} {lastname}
    <div>
        {*if state=='MA'}
            Employee from MA
        {*if <defined<state>>}, the state of Massachusetts{*endif}
	
        {*endif}
    </div><br>
{/employees}

Result:

Employee name:Fred Smith
Employee from MA , the state of Massachusetts

Employee name:Laura Linneker

Employee name:Junior Programmer
Employee from MA , the state of Massachusetts

Employee name:Bill Lindsey