Symprex Email Signature Manager, v5.5.1 |
Conditional Statements |
Conditional Statements is a very powerful feature in Symprex Email Signature Manager. They allow you to include or exclude part of a template based on whether or not there is data in a specific field. A common use of this feature is to avoid labels in front of empty fields.
If Conditional Statement
The $if conditional statement allows you to specify that the enclosed block of content should only be included if the specific field contains data.
The syntax for the $if conditional statement is:
{$if field}content to include when field contains data{$}
Example:
{$if mobile}Mobile: {mobile}{$}
Ifno Conditional Statement
The $ifno conditional statement allows you to specify that the enclosed block of content should only be included if the specific field contains no data or is null.
The syntax for the $ifno conditional statement is:
{$ifno field}content to include when field contains no data{$}
Example:
{$ifno mobile}Mobile: N/A{$}
Else Conditional Statement
The $if and $ifno statements can be combined with the $else statement to test for the inverse condition. This simplifies conditional statements as there is no need to define both $if and $ifno statements to test for a field value containing data or being empty.
The syntax for the $else conditional statement is:
{$if field}content to include when field contains data{$else}content to include when field contains no data{$}
Example:
Mobile: {$if mobile}{mobile}{else}N/A{$}
Testing if Field Is Equal To a Specific Value
The $if can be used to test if a field value is equal to a specific value by using the = operand and using the following syntax:
{$if field="value"}content to include when field is equal to the specified value{$}
Example:
Country: {$if countrycode="GB"}Great Britain{$else}Somewhere else{$}
The comparison is case insensitive.
Testing if Field Is Not Equal To a Specific Value
The $if can be used to test if a field value is not equal to a specific value by using the <> operand and using the following syntax:
{$if field<>"value"}content to include when field is not equal to the specified value{$}
Example:
Country: {$if countrycode<>"US"}Not the United States{$else}The United States{$}
The comparison is case insensitive.
Testing if Field Is Like a Specific Value
The $if can be used to test if a field value is like a specific value by using the % operand and using the following syntax:
{$if field%"value"}content to include when field is like the specified value{$}
The tested value can include the following wildcards:
Example:
Area Code: {$if phone%"0208*"}Outer London{$else}Somewhere else{$}
The comparison is case insensitive.
Additional Notes on Conditional Statements
When the "Remove trailing spaces from field values" option is enabled (configured through the Deployment Options dialog), any trailing spaces in field values will be removed before evaluating conditional statements. Field values that only contain one or more spaces will be trimmed to an empty value; this is desirable as such fields would generally be considered empty in relation to signatures.
When using conditional statements in HTML templates care needs to be taken to ensure that the correct HTML tags are either included or excluded in the conditional statement. This can be verified by checking the Source for the template in the template browser.
Avoiding Blank Lines
To avoid a blank line when a conditional statement that evaluates to false includes a whole full line, include the line break within the conditional statement. For example this template would result in a blank line between name and phone in signatures for users that do not have a mobile number:
{fullname} {$if mobile}Mobile: {mobile}{$} Phone: {phone}
To avoid the potentially empty line, the signature should be rewritten like this:
{fullname} {$if mobile}Mobile: {mobile} {$}Phone: {phone}
Note In HTML templates, you may need to either include or exclude line break tags (i.e. <br>) inside the end of the conditional statement to achieve the desired effect. When using paragraph tags (i.e. <p>...</p>), ensure that the tags will not become unbalanced by getting excluded by the conditional statement.
|
Copyright © 2014 Symprex Limited. All Rights Reserved. |