This topic describes ODR and Velocity salutation logics. By default, Optimizely Campaign uses ODR salutation logic.
Use your specific data and recipient list fields, and test the field functions before using them in a mailing.
ODR
Below you can find standard and special ODR salutation logics including field function templates.
ODR cannot display special characters as HTML codes. Since some email programs require the respective HTML codes to display special characters correctly, you must use Velocity for these cases.
Salutations without title
You can use the following ODR code for the personalized salutation Dear Mrs., Dear Mr. or Dear Sir or Madam:
<odr:set value="%{lower(user.data.salutation)}" var="salut"/><odr:set value="%{user.data.lastname}" var="lname"/><odr:choose> <odr:when test="%{not isEmpty(lname) and (salut eq 'mr' or salut eq 'mrs')}"> <odr:choose> <odr:when test="%{salut eq 'mr'}"> <odr:out value="Dear Mr." /> </odr:when> <odr:when test="%{salut eq 'mrs'}"> <odr:out value="Dear Mrs." /> </odr:when> </odr:choose> <odr:out value=" %{lname}" /> </odr:when> <odr:otherwise> <odr:out value="Dear Sir or Madam" /> </odr:otherwise></odr:choose>
Salutations with title
If your recipient list contains a recipient list field for the salutation title, you can display it with the following ODR code:
<odr:set value="%{lower(user.data.salutation)}" var="salut"/><odr:set value="%{user.data.title}" var="title"/><odr:set value="%{user.data.lastname}" var="lname"/><odr:choose> <odr:when test="%{not isEmpty(lname) and (salut eq 'mr' or salut eq 'mrs')}"> <odr:choose> <odr:when test="%{salut eq 'mr'}"> <odr:out value="Dear" /> </odr:when> <odr:when test="%{salut eq 'mrs'}"> <odr:out value="Dear" /> </odr:when> </odr:choose> <odr:choose> <odr:when test="%{not isEmpty(title)}"> <odr:out value=" %{title}" /> </odr:when> </odr:choose> <odr:out value=" %{lname}" /> </odr:when> <odr:otherwise> <odr:out value="Dear Sir or Madam" /> </odr:otherwise></odr:choose>
Mixed salutations
If you have different entries in the recipient list field for the salutation, you can use the following ODR code
<odr:set value="(m|1|male|mr|mr.)" var="male" /><odr:set value="(w|2|f|female|mrs|mrs.)" var="female" /><odr:set value="%{user.data.lastname}" var="lastname" /><odr:set value="%{lower(user.data.salutation)}" var="salutation" /><odr:choose> <odr:when test="%{!isEmpty(lastname) and (matches(salutation, male) or matches(salutation, female))}"> <odr:choose> <odr:when test="%{matches(salutation, female)}"> <odr:out value="Dear Mrs." /> </odr:when> <odr:when test="%{matches(salutation, male)}"> <odr:out value=Dear Mr." /> </odr:when> </odr:choose> <odr:out value=" %{lname}" /> </odr:when> <odr:otherwise> <odr:out value="Dear Sir or Madam" /> </odr:otherwise></odr:choose>
The code example assumes that the recipient list field contains the values M, 1, Male, Mr, Mr. or W, 2, F, Female, Mrs, Mrs..
If Mr and Mrs are queried, the female salutation must be given first, since Mr applies to both male and female. Otherwise, the male salutation is always displayed.
Multiple salutations
If you have multiple recipient list fields for different salutations, you can use the following ODR code as default replacement:
You must reference appropriate recipient list fields for both salutations and last names.
<odr:set value="%{lower(user.data.salutation)}" var="salut"/><odr:set value="%{user.data.lastname}" var="lname"/><odr:set value="%{lower(user.data.salutation2)}" var="salut2"/><odr:set value="%{user.data.lastname2}" var="lname2"/><odr:choose> <odr:when test="%{(not isEmpty(lname) and (salut eq 'mr' or salut eq 'mrs')) and (not isEmpty(lname2) and (salut2 eq 'mr' or salut2 eq 'mrs'))}"> <odr:choose> <odr:when test="%{(salut eq 'mrs') and (salut2 eq 'mrs')}"> <odr:out value="Dear Mrs. %{lname}," /> <odr:out value="<br>"/> <odr:out value="dear Mrs. %{lname2},"/> </odr:when> <odr:when test="%{(salut eq 'mr') and (salut2 eq 'mrs')}"> <odr:out value="Dear Mrs. %{lname2}," /> <odr:out value="<br>"/> <odr:out value="dear Mr. %{lname},"/> </odr:when> <odr:when test="%{(salut eq 'mrs') and (salut2 eq 'mr')}"> <odr:out value="Dear Mrs. %{lname}," /> <odr:out value="<br>"/> <odr:out value="dear Mr. %{lname2},"/> </odr:when> <odr:when test="%{(salut eq 'mr') and (salut2 eq 'mr')}"> <odr:out value="Dear Mr. %{lname}," /> <odr:out value="<br>"/> <odr:out value="dear Mr. %{lname2},"/> </odr:when> </odr:choose> </odr:when> <odr:otherwise> <odr:out value="Dear Sir or Madam" /> </odr:otherwise></odr:choose>
You must also add the following ODR code as text content:
You must reference appropriate recipient list fields for both salutations and last names.
<odr:set value="%{lower(user.data.salutation)}" var="salut"/><odr:set value="%{user.data.lastname}" var="lname"/><odr:set value="%{lower(user.data.salutation2)}" var="salut2"/><odr:set value="%{user.data.lastname2}" var="lname2"/><odr:set value="%{character('10')}" var="br"/><odr:choose> <odr:when test="%{(not isEmpty(lname) and (salut eq 'mr' or salut eq 'mrs')) and (not isEmpty(lname2) and (salut2 eq 'mr' or salut2 eq 'mrs'))}"> <odr:choose> <odr:when test="%{(salut eq 'mrs') and (salut2 eq 'mrs')}"> <odr:out value="Dear Mrs. %{lname}," /> <odr:out value="%{br}"/> <odr:out value="dear Mrs. %{lname2},"/> </odr:when> <odr:when test="%{(salut eq 'mr') and (salut2 eq 'mrs')}"> <odr:out value="Dear Mrs. %{lname2}," /> <odr:out value="%{br}"/> <odr:out value="dear Mr. %{lname},"/> </odr:when> <odr:when test="%{(salut eq 'mrs') and (salut2 eq 'mr')}"> <odr:out value="Dear Mrs. %{lname}," /> <odr:out value="%{br}"/> <odr:out value="dear Mr. %{lname2},"/> </odr:when> <odr:when test="%{(salut eq 'mr') and (salut2 eq 'mr')}"> <odr:out value="Dear Mr. %{lname}," /> <odr:out value="%{br}"/> <odr:out value="dear Mr. %{lname2},"/> </odr:when> </odr:choose> </odr:when> <odr:otherwise> <odr:out value="Dear Sir or Madam" /> </odr:otherwise></odr:choose>
Velocity
You can use the following Velocity code as standard replacement for the personalized salutation Dear Mrs., Dear Mr. or Dear Sir or Madam:
To convert special characters into HTML code, the Velocity code includes the function $HtmlUtils.encodeEntities()
.
#set($salutation = $!user.data.salutation)#set($lastname = $!user.data.lastname)#if (!$StringHelper.isEmpty($salutation) && !$StringHelper.isEmpty($lastname) && ($salutation.equals("Mr") || $salutation.equals("Mrs"))) #if ($salutation.equals("Mr")) Dear Mr. #else Dear Mrs. #end $HtmlUtils.encodeEntities($user.data.lastname)#else Dear Sir or Madam#end
You must also add the following Velocity code (without the function $HtmlUtils.encodeEntities()
) as single-line text content:
#set($salutation = $!user.data.salutation)#set($lastname = $!user.data.lastname)#if (!$StringHelper.isEmpty($salutation) && !$StringHelper.isEmpty($lastname) && ($salutation.equals("Mr") || $salutation.equals("Mrs")))#if ($salutation.equals("Mr"))Dear Mr. #else$!{null}Dear Mrs. #end$user.data.lastname#else$!{null}Dear Sir or Madam#end
Please sign in to leave a comment.