Using an email script token in the subject line | Community
Skip to main content
New Participant
July 13, 2015
Question

Using an email script token in the subject line

  • July 13, 2015
  • 3 replies
  • 5243 views

Tricky one here. I've used an email token to spit out a variable in an email program. But in Apple Mail and Outlook 2014 there are weird spaces inserted before and after the token. See below.

The token is £100 GBP. The random spaces are definitely not part of the code.

Weird things I found out:

* When I simply put the plain text of "£100 GBP" as the output of the email script, the weird spaces remain. So it's nothing to do with my code.

* When I use a Plain Text token instead of an Email Script token (effectively making the token static), it works fine.

This might be something purely in Apple Mail and Outlook (it looks fine in Outlook365.com, interestingly enough), but in any case I can't risk it. I had to use an alternative subject line instead of something dynamic.

Has anyone encountered this before? I've asked Support but basically since it's to do with email rendering they have said they can't help me.

Phil

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

New Participant
July 11, 2022

Hi!

I ran into the same issue. Try using a minifier tool on your code, it removes the fluff by removing all indentations.

Worked for me just fine. I've used this site: https://www.toptal.com/developers/javascript-minifier

SanfordWhiteman
New Participant
July 11, 2022

This doesn’t relate to indentation. It relates to the reserved Velocity character $ which must be escaped as ${esc.d}.

Michael_McGowa1
New Participant
July 22, 2022

If you are using a script token in the subject line, and also in the body, and the script is formatting the number to currency, is there a way to code this so that this spacing in the subject line does not happen?

 

This is what I have in script for the total

#set($total = $number.currency(${subtotal})) #set($stringLength = $total.length() - 3) #set($totalb = $total.substring(0,$stringLength)) ${totalb}

 

I have also tried just using number formatting instead of the currency formatting i.e.

#set ($formattedTotal = $number.format("number", $subtotal)) ${esc.d}${formattedTotal}

Yet, I still get the space in the subject line.

 

Edward_Unthank_
New Participant
July 13, 2015

Innnnnnteresting. I don't know why, but here could be some guesses for troubleshooting and finding the problem.

Can you count the number of spaces? Could be the scripting token is counting whitespace and rendering it in the subject line. Aka something like "echo '$100';" might count an extra whitespace.

Do you have the same problem if you just output the response (no code in the email script) with just "100" and not the special character?

Edward

Scott_McKeighe2
New Participant
July 13, 2015

Did you try making the entire string part of your Email Script token, not just the £100 GBP ? I'd try that to see if it alleviates the rendering issue.

New Participant
July 13, 2015

Weirdly, that's giving me a different error. Every variant has a currency in it (either a dollar, pound or euro sign) and when I put the entire string in the email script output, then put only the token in the subject line, then it either:

1. Shows "£100" if the string was meant to be "(string) £100 GBP (string)"

2. Shows "100" if the string was meant to be "(string) $100 (string)"

I think this is because Velocity is interpreting the string as purely the variable name. For example, I'm using lines such as:

#set ($LifetimeDepositFormatted = "Don't forget your £100 GBP Lifetime Deposit!") or

#set ($LifetimeDepositFormatted = "Don't forget your $250 NZD Lifetime Deposit!")

This might be interacting with the subject line in strange ways.