I'm trying to append the lead's language to unsubscribe html text via a token. Each piece seems to work correctly on its own. When I send a sample, the script inside of the token is just added to the end of the URL. My token is
#if(!$lead.language.isEmpty())
#if($lead.language.toLowerCase() == "english")
#set($LANG = "en" )
#else
#if($lead.language.toLowerCase() == "chinese")
#set($LANG = "cn" )
#else
#if($lead.language.toLowerCase() == "spanish")
#set($LANG = "es" )
#else
#if($lead.language.toLowerCase() == "portuguese")
#set($LANG = "pt" )
#else
#if($lead.language.toLowerCase() == "russian")
#set($LANG = "ru" )
#else
#set($LANG = "en")
#end
#end
#end
#end
#end
#else
#set($LANG = "en")
#end
$LANG
My Unsubscribe HTML is
<p style="background-color:#ffffff;"><div style="color: #4f4f4f; text-align: center; font-family: 'Gulfstream Horizon',Arial,sans-serif; font-size: 10.5px;">This email was sent to {{lead.Email Address}}<br><a style="color: #4f4f4f;" href="https://test.com/signup.html?mkt_tok=##MKT_TOK##&utm_source=marketo&utm_medium=email&utm_campaign={{my.campaign:default=mrk}}&{{program.name:default=na}}">Update preferences</a> | <a style="color: #4f4f4f;" href="%mkt_opt_out_prefix%UnsubscribePage.html?mkt_unsubscribe=1&mkt_tok=##MKT_TOK##&utm_source=marketo&utm_medium=email&utm_campaign={{my.campaign:default=mrk}}&{{program.name:default=na}}">Unsubscribe</a> | <a style="color: #4f4f4f;" href="https://test.com?lang={{my.Language}}&document=Privacy%20Notice">Privacy notice</a></div></p>
Solved! Go to Solution.
Ultimately what worked was to add the full anchor tag (<a> to </a>) to the token script. Then I referenced the token normally {{my.token}} to the Unsubscribe HTML field.
Hi Jason,
First, you should be using equalsIgnoreCase() instead of repeatedly converting to lower case. equalsIgnoreCase() is more efficient and more accurate.
#if( $lead.language.equalsIgnoreCase("chinese") )
equals() is also more accurate than ==, which has bugs, for future reference.
Now, to this particular situation. The only supported way to use Velocity with links is to emit the entire link from Velocity (<a> through closing </a>). However, knowing some special things about the unsubscribe HTML, I'm going to make the somewhat unexpected recommendation that you move the Velocity code inside the input box, rather than including the {{my.token}}. Let me know what happens with that.
Thank you for the tips. I have updated the logic, but I get an error when I try to add the Velocity code into the Unsubscribe HTML field and approve.
Validation Error approving TEST 5 Languages_DZ.TEST 5 Languages_DZ — <div>An error occurred when procesing the email Body! </div> <p>Encountered "#else\n" near</p> <div><pre > #set($LANG = "en" )</pre><pre > #else</pre><pre class="x-form-item-label"> #if($lead.language.equalsIgnoreCase("chinese"))</pre><pre > #set($LANG = "cn" )</pre><pre > #else</pre></div>
OK, that sounds standard; the Unsubscribe HTML is non-standard in certain ways so that's why I thought you might have to skip the usual.