Substituting Email Blocks According to Contact Profile Data

The Velocity code allows you to create an email with content depending on the data in the contact's profile, e.g., gender. Men will see a selection of products for men, women — for women, and those contacts whose gender is not specified — a common product selection.

Setting Up Dynamic Blocks

  1. Place three structures with content for different segments in the template: women's clothing, men's clothing, and a common product selection.
  1. Select the structure with women's products and open its code editor.
  1. Declare a variable from the contact profile above the first tr tag. In our case, this is an additional contact field %PERSONAL.GENDER%.
🚧

Important

The variable's name in the template must match the name of the additional contact field, which you can see in the account settings on the Additional fields tab. Read more about contact fields in the manual.

  1. Add a conditional statement to the code. Use the following format:
<!--#if($data.get('parameter name')=='value1')-->
📘

Note

The data retrieval command data.get is required only when accessing recommendation or external data sources. In all other cases, you can also use the format described in the Velocity 2.4.1 documentation. For example:

FormatVariableDescription
Shorthand$discountIf the variable does not exist, the literal text $discount is output
Silent$!discountIf the value is missing, nothing is rendered
Formal${discount}Braces unambiguously delimit the variable name from adjacent text
Silent formal$!{discount}Properly delimits the variable and suppresses missing values
Alternate value${discount|Free Shipping}If the variable value is missing, a fallback value is inserted

In our case, the operator will be like this:

 <!--#if($data.get('PERSONAL.GENDER')=='F')-->
  1. Select the structure with men's products. You will see the structure’s code in the editor.
  1. Add a conditional statement to the code above the tr tag. Use the following format:
<!--##elseif($data.get('parameter name')=='value2')-->

In our case, the operator will be like this:

 <!--#elseif($data.get('PERSONAL.GENDER')=='M')-->
  1. Select the structure with the common products.
  1. Add a conditional statement to the code above the tr tag. Use the following format:
<!--#else-->
  1. Add an end statement after the tr tag that closes the structure.
<!--#end-->

You can make a more complex check in case the fields have different cases: M or m, F and f:

#if($data.get('PERSONAL.GENDER')=='m') and $data.get('PERSONAL.GENDER')=='M')

You can also use such option:

#if($data.get('PERSONAL.GENDER').equalsIgnoreCase('m'))

Similar articles: