Extra whitespaces surrounding tokens

SanfordWhiteman
Level 10 - Community Moderator

Re: Extra whitespaces surrounding tokens

Well, then you probably have an extra CR in the output.  Remember, Velocity is not purely for HTML output -- that is, 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.

Anonymous
Not applicable

Re: Extra whitespaces surrounding tokens

If there were an extra space in the output wouldn't that result in the biz name having a space after it in EVERY instance it's used? As mentioned, it's only happening when we use this token before punctuation. I'm not entirely sure what at CR is, but I''ll forward your note to the engineer who made this token. Not seeing any obvious spaces when I look at the script:

#set($AcctName = ${Account_Contact__cList.get(0).Account_Name__c})

#if ($AcctName)

$AcctName

#else your business#end

SanfordWhiteman
Level 10 - Community Moderator

Re: Extra whitespaces surrounding tokens

Unless you can provide a full dump of the HTML with and without the token, and the full text of the Velocity script (hard to paste this accurately into the Community, unfortunately, since the editor changes whitespace) it's impossible to verify what's happening. 

But the idea that the token output changes based on the characters after it doesn't make any sense. The Velocity parser doesn't "peek ahead" at what's next before deciding what to output.

And again, I can't repro this behavior. A ? after a token doesn't add any additional characters.

2016-10-10 15_24_31-Program Lab 09.Lab - VTL tests 02.png

2016-10-10 15_22_10-Marketo Email Previewer _ Program Lab 09.Lab - VTL tests 02.png

Anonymous
Not applicable

Re: Extra whitespaces surrounding tokens

Yeah I don't think I'd be allowed to do that, BUT we have the exact same token in another email that DOESN'T have the issue before punctuation. There is literally no difference in the token at all, yet it works fine. We copy and pasted the script from the one token to the other and the issue is solved. Still no real explanation, but we changed nothing in the html so it definitely does seem to be related to the token.

SanfordWhiteman
Level 10 - Community Moderator

Re: Extra whitespaces surrounding tokens

Copy and pasting removes some special (high) characters from text. So you probably had a trailing special character in there that you couldn't see (for example, a zero-width space).

Rajesh_Khatri
Level 2

Re: Extra whitespaces surrounding tokens

Hi Sanford, 

 

I have created velocity token script for captilising the first letter of field First Name. But the problem is it is giving a whitespace after a token. 

 

For example: If I am using the token in email, it gives me as following 
Hi Sanford ,

 

I want to remove the space between name and comma. I tried your method .tostring().trim() but it did not work. Here below is my script. Can you help me with code that can remove the white space.  

 

#set($name = ${lead.FirstName})
#if(!$name.isEmpty())
${name.substring(0,1).toUpperCase()}${name.substring(1).toLowerCase().toString().trim()}
#end
 

Regards

Rajesh Khatri

Wyatt_Bales4
Level 4

Re: Extra whitespaces surrounding tokens

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."

Anonymous
Not applicable

Re: Extra whitespaces surrounding tokens

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

Rachel_Noble
Level 10 - Champion Alumni

Re: Extra whitespaces surrounding tokens

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

Re: Extra whitespaces surrounding tokens

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. 

SpaceAfterToken.png

 ScriptOutputNoSpaces.pngScriptOutputNoSpaces_Tokens.png