Can Velocity be output without line breaks occurring?

Casey_Grimes
Level 10

Can Velocity be output without line breaks occurring?

I'm currently running into an issue where I'm experiencing a styling issue due to the actual line break of the output HTML. Essentially, because the Velocity output in the raw HTML of an email includes one to several line breaks, email/web clients will not correctly pick up an anchor within a span as being all together. This behavior does not happen when all content is inline.

"HTML shouldn't render differently depending on line breaks!", you say. I agree, and yet here we are: https://codepen.io/cougrimes/pen/a6b14801a79e2aaab25cc729d09b9504 

This behavior occurs in every major email client. Is there any way to force Velocity output to be solely inline?

Tags (1)
5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: Can Velocity be output without line breaks occurring?

Well, Velocity is strictly whitespace-preserving. So if there's a line break at the end of a line, Velocity won't ignore it. (This is a very good thing in general because you couldn't output plain text otherwise.)

But if you end a line with a Velocity comment, there is no line break.

${myOutput}##
Casey_Grimes
Level 10

Re: Can Velocity be output without line breaks occurring?

Unfortunately, the problem isn't solved by commenting out to prevent a standard return/newline--even when all parts of the code have comments to stop the line, the raw output generated by Marketo is

<span class="vib">


Si vous avez du mal à afficher le présent courriel, <a href="#" id="std-view-as-webpage" style="text-decoration: none;" class="vib">


cliquez ici pour l'afficher en ligne</a>



.</span>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


As a result, you still get the improper behavior.

SanfordWhiteman
Level 10 - Community Moderator

Re: Can Velocity be output without line breaks occurring?

What is the Text-Only output of such an email?

What's the actual Velocity you're using?

Casey_Grimes
Level 10

Re: Can Velocity be output without line breaks occurring?

Text-only output also renders a space for some reason:

[ cliquez ici pour l'afficher en ligne](#) .

Token placement is just

<span><a href="#">{{my.token1}}</a>{{my.token2}}</span>

Tokens themselves are just checking against a defined reference done elsewhere after being converted to strings and trimmed off, then running through a couple #if/#else checks, so you wind up having something a la

#if($lang == "fr")
cliquez ici pour l'afficher en ligne##
#else
View it in your browser##
#end

The same process happens in token1 and token2 (as there are times when there needs to be suffix text and times where simply ending the sentence suffices). 

SanfordWhiteman
Level 10 - Community Moderator

Re: Can Velocity be output without line breaks occurring?

Look deeper into the earlier part of your code. Don't think this space is spontaneously occurring.