Re: Referencing local tokens in an email Velocity email script token

Anonymous
Not applicable

Referencing local tokens in an email Velocity email script token

Is there a way to create a velocity email script token (is there a way to write a Velocity script) that can call on any other tokens, i.e. text my.tokens in the same program?

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Referencing local tokens in an email Velocity email script token

Velocity can access variables (VTL references) set in other Velocity {{my.tokens}} embedded in the same email asset (they don't technically have to be from the same program, they can be inherited).

It can't access text or other {{my.token}} types.

In Velocity-heavy environments it's common to create "data tokens" like so:

#set( $myVeloVar = "Some text" )

Then you can use that reference in other, later tokens:

$myVeloVar

There are even ways to embed data blocks without a literal #set statement but they're rather far afield.

Anonymous
Not applicable

Re: Referencing local tokens in an email Velocity email script token

Thank you for your response and knowledge!

shawn

Carlito_Jay_Ala
Level 2

Re: Referencing local tokens in an email Velocity email script token

Hey @Sanford, Thanks for your input here, but that's a bummer.

Program tokens inside an email script is my last resort. Do you know any other way to populate program tokens dynamically into an email?

EX. If X Field = X Value Display my.token1 Else if X field = Y Value Display my.token2

Any suggestions is greatly appreciated. Thanks! 🙂

Carl

stmpjmpr
SanfordWhiteman
Level 10 - Community Moderator

Re: Referencing local tokens in an email Velocity email script token

If you don't consider segments an alternative, then conditional output is done w/Velocity... that's what it's there for!

Also, in case it isn't clear, you can have your output values in their own Velocity tokens, where they are managed exactly like text tokens:

pastedImage_5.png

pastedImage_2.png

pastedImage_4.png

pastedImage_1.png

pastedImage_3.png

pastedImage_0.png

Of course you would only do this to preserve the user experience of editing a token (since they can edit {{my.output1}} and {{my.output2}} here and can't mess anything else up). I try to avoid this method because VTL is verbose enough as it is.