SOLVED

Re: Email Script Token type in Unsubscribe

Go to solution
Jason_Saunders
Level 2

Email Script Token type in Unsubscribe

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>

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jason_Saunders
Level 2

Re: Email Script Token type in Unsubscribe

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.

View solution in original post

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script Token type in Unsubscribe

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.

Jason_Saunders
Level 2

Re: Email Script Token type in Unsubscribe

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 - Community Moderator

Re: Email Script Token type in Unsubscribe

Can you trim it down to the smallest possible code chunk that triggers the error (in the Unsub HTML)?
Jason_Saunders
Level 2

Re: Email Script Token type in Unsubscribe

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.

SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script Token type in Unsubscribe

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.