If-Then-Else Rules


Table of Contents:

If-Then-Else Rules

Dynamic Content Blocks Using if-then-else Conditions

With this feature you can use if-then-else statements within your email message in order to display different content to different users based on different values residing in their list field.

  • Let's say you have a list field named 'city'. Then using if-then-else condition statements you can send different content to for different cities, all in the same email and campaign. So for example if city  = Boston display an HTML content block about the Red Sox else if city = Atlanta display a content block about the Atlanta Braves.

Dynamic content blocks can be implemented using if-then-else statements as demonstrated below:

{{ocx_if field = value}}
some content
{{ocx_elseif field = other value}}
some other content
{{ocx_else}}
default content
{{ocx_endif}}

<!–– You can use multiple if-then-else blocks in the same email message ––>

{{ocx_if field = value}}
some content
{{ocx_elseif field = other value}}
some other content
{{ocx_else}}
default content
{{ocx_endif}}

<!–– You can even use Nested if-then-else blocks ––>

{{ocx_if Field1 = Field1_V1}}
   inside 1st level if, before 2nd level if
   {{ocx_if Field2 = Field2_V2}}
       inside 2nd level if, before 3rd level if
       {{ocx_if Field3 = Field3_V3}}
           inside 3rd level if
       {{ocx_endif}}
       inside 2nd level if, after 3rd level if
   {{ocx_endif}}
   inside 1st level if, after 2nd level if
{{ocx_endif}}
  • Operators currently supported are:
    • =><>=<=
    • contains, !contains, begins_with, !begins_with, ends_with, !ends_with
  • Each operator can be negated by putting an exclamation mark ! before it in the following manner:
    • e.g {{ocx_if some_list_field != 100}} 
  • To check if the value of a dynamic list field is empty use: is empty you can also use is null.
    • As in this example: {{ocx_if some_list_field is empty}} 
    • For not empty use the logical NOT character ("!") in the following manner: {{ocx_if some_list_field !is empty}} 
  • (warning) There must be a space between field, operator and value, as in the following manner: country = Canada (and NOT country=Canada)

You can also use multiple AND/OR conditions in the following manner:

ocx_if a > b AND c > d
ocx_if a > b OR c > d
ocx_if a > b AND c > d AND e > f

For example:
{{ocx_if product = 159450 OR category = Apparel }}
{{ocx_if address !is empty AND city !is empty AND state !is empty}}

(warning) Note: Ongage supports if-then-else statements only with Email messages (not SMS).

(warning) Note: AND/OR must be in caps.

(warning) Note: In the case of Date fields the format used in the condition should be the same as defined in your List → List Settings → Fields Setup.

(info) These statements can be used both in SMTP and ESP vendors, with the above restrictions.

Using if-then-else in the Email Subject and Pre-Header 

(info) You can use if-then-else in the Email Subject and Pre-Header as illustrated below:
(warning) When using the if-then-else condition in Email Subject, do not leave any space and the whole condition must be written like a paragraph.

Using If-then-else in X-Header replacement tag

You can use "if-then-else" conditions as part of the Email X-Header replacement Tag, which is one of the ways to set custom email message headers in Ongage. You can use both or either List fields and System fields.
Below is an example where "email_key" is a List field, and "ocx_campaign_name" is the system field. In this example, the system will check first if "email_key" is not empty and populate the custom header with it, otherwise if it is empty, then the system will populate the custom header with the Campaign name . 

[[0:header_X-SOME-HEADER-NAME:{{ocx_if email_key !is empty}}{{email_key}}{{ocx_else}}{{ocx_campaign_name}}{{ocx_endif}}]]

Please Refer to our X-Header Replacement Section for more details.