3 very crucial questions regarding Apache Velocity email script tokens in an email | Community
Skip to main content
June 1, 2017
Solved

3 very crucial questions regarding Apache Velocity email script tokens in an email

  • June 1, 2017
  • 2 replies
  • 5971 views

Background: I have an email script that initializes a bunch of variables and then other smaller individual scripts that reference the initial variables. This works in the HTML email and plain text email, but there are 3 significant problems.

1. Where can I place my initial script token so that the other email scripts will populate in the subject line?

2. The initial email script token results in a lot of whitespace in the plain text version of the email. Since I have to place it at the very beginning of the email, the email has like 10 lines of whitespace at the top.

3. How do I properly create a link using an email script?

The way I have it now:

In the token:

#set ($directions = "google.com/maps/dir//Some+Place")

$directions

So here $directions is being printed — the actual link, that is.

In the HTML:

<a href="{{my.token}}">Directions</a>

The error I get in Safari: (see attachment)

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

I can output the whole thing from VTL, but only for one particular link value. For instance, if the script token outputs a value of: <a href="link">My Link</a> it CANNOT ALSO output a value of say <a href="link">Another Link</a> or <a href="link"><img src="image"></a>. It can only do one!

What I'm trying to accomplish is have the email script output a link, like "$mylink" scattered around an email: sometimes being linked to a single word, another time to a full sentence, and then maybe again to an <img>. But again, the problem I face is that if I have to include both the opening and closing anchor tags in the script itself, then the value that lies between the tags is static.


Yes, you'd have to find a way to make the inner text and/or elements generated in Velocity as well.  Combining VTL-contributed HTML pieces (in token/s) with end-user-contributed pieces (in the email body itself, including in variables) is difficult-to-impossible.

A notable exception is using comment tokens (containing just the text "<!--" and "-->"), but that's for suppressing user content as opposed to merging VTL+user content in a functional way.

Standalone text or elements from each source can be combined, of course, but trying to construct <element>s from pieces of both is almost guaranteed to fail.

2 replies

June 1, 2017

I've been able to fix #1 and #2, but #3 is still problematic! Any help/suggestions/followup is super, super appreciated!

For those who are interested...

#1 appeared to be a Marketo bug, because I can't trace how it was fixed.

#2 was fixed by including the initializing email script token in the subject line itself. Works like a charm.

#3 is still being a pain.

SanfordWhiteman
Level 10
June 1, 2017

Always output a fully-formed A tag from Velocity. And within VTL, use the same rules as within email content: hard-code the http​s:// (don't have that in a VTL reference).

June 1, 2017

Excuse my ignorance, what does VTL stand for? Also, that won't work with the plain text version of the email though, correct?

Any way to get one token to populate a link in HTML and in plain text ​properly​?

SanfordWhiteman
Level 10
June 1, 2017

VTL = Velocity Template Language.

This might help: http://blog.teknkl.com/polymorphic-tokens/