Re: Can Velocity process program tokens?

Anonymous
Not applicable

Can Velocity process program tokens?

If I just want to pass an array of values through an API call as a program token, can I use a Velocity token to format those values? If so, how?

Example:

{{my.ProductList}} = "Name1~ImageUrl1|Name2~ImageUrl2" (or could be json or some other format)

{{my.VelocityScript}} ==> <table><tr><td>Name1</td><td><img src='ImageUrl1'><td></tr><tr><td>Name2</td><td><img src='ImageUrl2'><td></tr></table>

I would just like to NOT have to do email presentation in my source application. I can't think of any other way, but I'm not sure if Velocity can even process program tokens.

Tags (2)
7 REPLIES 7
Anonymous
Not applicable

Re: Can Velocity process program tokens?

Hi Colin

I just tested this, and couldn't get it to work. I've also once read that the "Calendar File"-token is the only token that can refer to other program tokens.

SanfordWhiteman
Level 10 - Community Moderator

Re: Can Velocity process program tokens?

Aside from a certain trick I won't get into now, Velocity *can* process Program Token content -- if the other tokens are also Velocity tokens! This is why I use VTL in lieu of text tokens much of the time.

BUT! The problem is the temporary tokens you can pass via API don't support VTL. Whether an oversight or a bug, this is the main problem in your scenario.

If you can update a VTL token first using the Asset API, that works, but not all apps will work with this sort of timing.

Rachit_Puri2
Level 7

Re: Can Velocity process program tokens?

Hi Sanford, can you share some example, where you used program level script tokens within a script token? I would like to try it at my end, but want to see how it really works.

SanfordWhiteman
Level 10 - Community Moderator

Re: Can Velocity process program tokens?

Sure.

One example is including data (non-output) {{my.dataToken}} like this in the <head>:

#set( $language = "en-us" )

Then you can reference any of its variables in a subsequent {{my.outputToken}}:

Your language is ${language}!

This works because Velocity uses a persistent (i.e. reusable/reentrant) global context.  Each time you reenter the Velocity world, you see all its variables.

I use this approach almost all the time, where data tokens are kept separate from output tokens. You can't make Velocity into a pretty language, but you can make it a lot like a real language in terms of separation of concerns, etc.

The pattern I call polymorphic tokens also takes advantage of the same functionality: http://blog.teknkl.com/polymorphic-tokens/

As I said above, the dream is to be able to pass temporary VTL tokens to Request Campaign. Unfortunately, this won't work now, and the static value of the token will be used instead.

Anonymous
Not applicable

Re: Can Velocity process program tokens?

Ugh, this is terrible. We're trying to migrate our transactional emails into Marketo, and this problem is causing all sorts of issues.

We want to be able to do something like this from our product, after certain actions have happened:

Marketo API -> Trigger Campaign(ProgramTokenList: {errors: ["error1", "error2"})

And then in the email:

#IF(errors) <some HTML with the errrors .. ideally a loop> #ENDIF

I thought I'd be able to use Velocity, but it seems like this is impossible - we can't check the values of the program tokens from inside the email script, which significantly reduces the value of being able to programatically trigger emails.

Am I missing something here? If I've read this thread correctly, there's no way to get this doing what I want. Or is there some newer, fancier solution that can make this work?

Anonymous
Not applicable

Re: Can Velocity process program tokens?

To be clear, I'm not in any way affiliated with Marketo, despite the display name. This is a shared account I use at my firm.

SanfordWhiteman
Level 10 - Community Moderator

Re: Can Velocity process program tokens?

I thought I'd be able to use Velocity, but it seems like this is impossible - we can't check the values of the program tokens from inside the email script, which significantly reduces the value of being able to programatically trigger emails.

That's correct. You can't pass Velocity tokens as "runtime tokens" -- those {{my.token}} values that only exist in the context of a "Request Campaign" execution. Only standard token types work there.

Workarounds to do what you describe are:

  • do whatever display logic you would've done in Velocity in your client app instead, then pass a text {{my.token}}
  • set a textarea field on the lead to contain error block, then trigger on Data Value Changed to launch the campaign  -- keeping the obvious race condition in mind since different runs won't be siloed from one another