Email Script Token type in Unsubscribe | Community
Skip to main content
Level 4
May 17, 2021
Solved

Email Script Token type in Unsubscribe

  • May 17, 2021
  • 1 reply
  • 3147 views

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&nbsp;preferences</a>&nbsp;|&nbsp;<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>&nbsp;|&nbsp;<a style="color: #4f4f4f;" href="https://test.com?lang={{my.Language}}&document=Privacy%20Notice">Privacy notice</a></div></p>

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by jjsaunders
Can you trim it down to the smallest possible code chunk that triggers the error (in the Unsub HTML)?

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.

1 reply

SanfordWhiteman
Level 10
May 18, 2021

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.

Level 4
May 18, 2021

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 = &quot;en&quot; )</pre><pre > #else</pre><pre class="x-form-item-label"> #if($lead.language.equalsIgnoreCase(&quot;chinese&quot;))</pre><pre > #set($LANG = &quot;cn&quot; )</pre><pre > #else</pre></div>
SanfordWhiteman
Level 10
May 18, 2021
Can you trim it down to the smallest possible code chunk that triggers the error (in the Unsub HTML)?