Symprex Email Signature Manager, v9.6.2

Conditional Statements

Conditional Statements is a very powerful feature in 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 statement can be used to test if a field value is equal to a specific value by using the = operator 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 statement can be used to test if a field value is not equal to a specific value by using the <> operator 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 statement can be used to test if a field value is like a specific value by using the % operator 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:

 

* matches any combination of characters and/or digits.

? matches any single character or digit.

# matches any single digit.

 

Example:

 

Area Code: {$if phone%"0208*"}Outer London{$else}Somewhere else{$}

 

The comparison is case insensitive, and matched characters include punctuation marks, symbols and separators such as spaces.

 

AND and OR Operators

 

Conditional statements support multiple comparisons in a single statement using the logical AND ($and) and OR ($or) operators, which combine the logical result from each comparison in the order in which they appear in the statement (i.e. the operators are evaluated from left to right with no precedence). For the AND operator to give a logical result of TRUE, both comparisons must give a logical result of TRUE. For the OR operator to give a logical result of TRUE, only one of the comparisons need give a result of TRUE. The syntax for using the operators is as follows:

 

{$if conditionOne $and conditionTwo $and conditionThree...}content to include when all of the conditions are TRUE{$}

{$if conditionOne $or conditionTwo $or conditionThree...}content to include when one of the conditions is TRUE{$}

 

Examples:

 

{$if firstname $and lastname}{firstname} {lastname}{$else}{fullname}{$}

{$if firstname="John" $and lastname="Smith"}John Smith{$else}Not John Smith{$}

{$if firstname<>"John" $or lastname<>"Smith"}Not John Smith{$else}John Smith{$}

 

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 © 2024 Symprex Limited. All Rights Reserved.