SOLVED

Re: Velocity token - salutation emails

Go to solution
Katia_Piton
Level 2

Re: Velocity token - salutation emails

Dear Tom, could you please share your latest script (the one which works ) with us please? I have the same one to implement in French ... many thanks!

Tom_Liolios4
Level 4

Re: Velocity token - salutation emails

Hi Guillaume, apologies for the belated reply. Hereby the code I'm using for salutation. This is the example for Dutch, but you can easily adjust for any language.

Note: do not forget to link the corresponding fields in the selection menu on the right when setting up the velocity script.

#set( $currentLang = "nl" )

#set( $salutations = {

  "nl" : {

    "Male" : "Beste meneer ${lead.LastName},",

    "Female" : "Beste mevrouw ${lead.LastName},",

    "" : "Beste ${lead.Full_Name},"

  }

} )

#if( $salutations[$currentLang].containsKey(${lead.Gender__c}) )

${salutations[$currentLang][${lead.Gender__c}]}

#else

${salutations[$currentLang][""]}

#end

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity token - salutation emails

Tom, better to take out the ${formal} notation (extra curly braces) unless you're inside double quotes or on an output-only line:

#set( $currentLang = "nl" )

#set( $salutations = {

  "nl" : {

    "Male" : "Beste meneer ${lead.LastName},",

    "Female" : "Beste mevrouw ${lead.LastName},",

    "" : "Beste ${lead.Full_Name},"

  }

} )

#if( $salutations[$currentLang].containsKey($lead.Gender__c) )

${salutations[$currentLang][$lead.Gender__c]}

#else

${salutations[$currentLang][""]}

#end

(In case anyone is wondering, the logic is not limited to binary male/female, it just happens to have only those plus the default/empty string "" listed at present.)

Silvia_Schlatte
Level 1

Re: Velocity token - salutation emails

@SanfordWhiteman You're script is awesome. I am wondering how we could merge different languages into one script / token,

if we are using dynamic content and language segments in our emails.

 

Currently, we do have set up one token per language... but this is very prone to error. If you do forget to change the token in the dynamic content. Could you help with this? 

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity token - salutation emails

Sure, the code is already set up for that – it's supposed to be one shared single object ("{}" in Velocity creates an object, technically a map object) with a key (named property) for each language, i.e.:

 

#set( $salutations = { 
  "nl" : { 
    "Male" : "Beste meneer ${lead.LastName},", 
    "Female" : "Beste mevrouw ${lead.LastName},", 
    "" : "Beste ${lead.Full_Name}," 
  },
  "fr" : { 
    "Male" : "Monsieur ${lead.LastName},", 
    "Female" : "Madame ${lead.LastName},", 
    "" : "Bonjour ${lead.Full_Name}," 
  } 
} )