Extra whitespaces surrounding tokens | Community
Skip to main content
August 15, 2016
Question

Extra whitespaces surrounding tokens

  • August 15, 2016
  • 5 replies
  • 6234 views

Hello.

I'm trying to use tokens in my emails, but I encountered with following problem: when I write sth like "{{my.token}}." there is a space between my token and a dot in a resulting email. As I understand it's because of line breaks that surround subsituted token in html code of email.

Is there any way to get rid of that line breaks and that space character?

Thanks!

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

5 replies

Jim_Thao7
Level 8
August 15, 2016

Can you provide screenshots or examples of what the value of your token is and how it resolves?

Are you saying that {{my.token}} where the token value = "something" resolves as "something ."?

August 16, 2016

Nope, {{my.token}}. renders as "something ." (note the space before dot). In the example below, the price is my token and there is an extra space between dot and token, which is missing in the email editor.

In the HTML code of rendered email you can see a linebreak right after my token which results in a space between token and dot

Jim_Thao7
Level 8
August 16, 2016

I feel like maybe there is a hidden character here.  Was the value "(US $89.00 per year)" copied over from somewhere? Perhaps you also copied over a hidden character of some sort. 

I would recommend that you retype this value out manually into the token to see if that helps.  Similarly, try copying and pasting this into notepad 2 or notepad++ to see if the hidden character can be revealed.

August 15, 2016

As I understand it's because of line breaks that surround subsituted token in html code of email.

Are these line breaks your additions to the HTML, or are you saying they are contained in the field (for example, a field that originated from a textarea)?

If they're in the HTML, remove 'em!

If they're in the field, you can pass the field through a Velocity (email scripting) template to massage the data, if necessary.

August 16, 2016

Nope, I suggest that these linebreaks are added by Marketo. The possible solution is to add the dot to the token but it reduces it's flexibility (for example, if I want to use that token in the middle of a sentence and at the end of it, I'll need to create two tokens instead of one)

SanfordWhiteman
Level 10
August 16, 2016

Text {{my.tokens}} don't just add linebreaks.  Please go to Email Actions >> HTML Tools >> Download HTML and post a snippet of several lines before and after the token is inserted.

Level 4
March 30, 2017

I've seen this for multiple customers. Adding '##' after the desired output fixes it for me.

#elseif ($lead.attribute == "XYZ")

Display this##

Before it would show "... Display this ."  now it shows "... Display this."

March 29, 2018

@Wyatt Bales​, that was a great (and easy) fix!

Level 8
March 30, 2017

We've had the same problem, and I think it's the source code from our templates re-formatting the HTML to add unwanted line breaks when we approved the emails. There's probably a better solution, but whenever I encounter this, I create a richtext token that has the value I want. Set a richtext toekn {{my.workaround}} = {{my.token}}. (including the period) and enter that in its place.

Not ideal, but worked for me multiple times.

Milena_Mitova
Level 2
October 15, 2019

Hi there, I found out that in addition to the above proposed solution (## at end of each line),  you need to check if you have extra unused lines in the script - it always creates space (see empty line #3 below) - so make sure you remove those as well:). Hope it helps:

#set($timeZoneObject = $date.getCalendar().getTimeZone())
$date.format("yyyy", $date.getDate(), $date.getLocale(), $timeZoneObject.getTimeZone("EST"))

Image 1 below shows the space. Once I deleted the 3rd line, the space after My.Year token is not showing any more. 

 

SanfordWhiteman
Level 10
October 15, 2019

That's right, Velocity is strictly space-preserving, as I mentioned above:

if you have whitespace, it's preserved by default, because you might be outputting into plain text (not just plain-text email but any old text file) where CRs are critical for proper formatting.

So there isn't actually such a thing as an "unused" line -- a trailing CR is as important as any other CR.

If you want whitespace in your code for readability, it can help to use #define blocks instead of direct output.

For example:

#define( $output )



This

has

line

breaks

before

and

after



#end
${output.toString().trim()}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The, er, defining of the #define doesn't output anything. Output is managed by String-ifying the #define and then trim()-ing it first. So the final email wouldn't have the before and after linebreaks.

See also https://nation.marketo.com/community/product_and_support/blog/2018/09/22/in-velocity-tokens-trim-your-defines