Velocity directly in template modules

Jo_Pitts1
Level 10 - Community Advisor

Velocity directly in template modules

Good afternoon all.

is it possible to write velocity code directly against a module in an email template, or do I need to abstract it by referencing a script token in the template?  

I'd like to build out a module that has the ability to comment itself out (often referenced here) without needing to add tokens in the email itself, and am curious as to best practice.

Cheers

Jo

7 REPLIES 7
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity directly in template modules

It is possible to write a limited amount of VTL directly in a template (this is the reason that there are reserved words in templates). However, this is in no way supported, and I advise as strongly as possible that you not rely on it.

 

If you want to conditionally comment out a section, you should wrap it in Velocity {{my.token}}s.

Jo_Pitts1
Level 10 - Community Advisor

Re: Velocity directly in template modules

Makes sense (and yes, I was already predicting problems with reserved characters).

 

Next silly question - can module variables be referenced in Velocity.  E.g., I set the a variable called 'colour' to 'BLUE' on the module, and then depending on whether a lead has a checkbox 'loves_blue' checked leave the module on display, otherwise comment it out?

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity directly in template modules

Unfortunately not, those vars can't be used in VTL.
Jo_Pitts1
Level 10 - Community Advisor

Re: Velocity directly in template modules


@SanfordWhiteman wrote:
Unfortunately not, those vars can't be used in VTL.

OK.. so imagine this.. I have three check boxes on the leads table... Loves_Blue, Loves_Red, Loves_Green.

I want to be able to create an email that displays a story on blue for lovers of blue, a story on red for lovers of red etc.  If someone has multiple checkboxes checked, then they see multiple stories.

I don't marketers to have to be in the code, just ideally selecting the colour the story relates to.

Thoughts on how best to achieve that?

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity directly in template modules

The marketer wouldn't need to edit any code.

 

You just put (at the template level) begin/end tokens with easily understood names:

 

2020-02-19 02_25_46-Marketo _ Program Lab 7270 - VTL block macro (My Tokens) • Marketing Activities.png

The editable areas go in-between those tokens.

 

Each pair of tokens contains lightweight code to determine whether the stuff inside is output for each recipient, i.e. by matching a lead field against the color "blue".

Jo_Pitts1
Level 10 - Community Advisor

Re: Velocity directly in template modules

Sanford,

Yep - there is that option.  However, there are 28 variants.

My dream is that I could have a module where the user says 'this story relates to this interest (1 of 28)' and then use velocity to include or exclude.

e.g. Three copies of my story module in a Newletter email.  If there were two stories with the interest A set, then a lead with an interest in A would see two stories.  If there was a story with an interest of B set, then a lead with an interest of B would see one story.  Obviously, if a lead had interests in A and B, then they'd see three stories.  

I guess I'll just have to create a LOT of begin and end tokens 🙂

Cheers, and (as always) thanks for the help.

Jo

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity directly in template modules

Yes. There isn't any way to tag a module using a mktoVariable in a way that Velocity can understand. You have to tag it by wrapping it in begin/end tokens. Although actually you don't need a special end token. It can be the same {{my.endStory}} for all of them.