Using {{program.id}} inside velocity?

Caleb_Kelly
Level 2

Re: Using {{program.id}} inside velocity?

Hi Chris - Were you ever able to make this work? We have been looking for a similar workaround for a while now.

Chris_Wilcox
Level 9

Re: Using {{program.id}} inside velocity?

Nope, I abandoned this idea and went instead to try to get Asset ID (which I could then, via the API, associate back to a program ID since an asset can only exist in 1 program). 

 

I did KIND OF get asset ID working. It worked in the sense that the code does dynamically populate the asset ID of the email it's within, however my goal was to use the script to populate a querystring element with that emails' Asset ID to associate pageviews to individual emails dynamically and at scale, but the velocity script does not run if it's included as a part of a TRACKED link. Works perfectly in an email body or in the HTML, or even an untracked link.  But as soon as you try to use velocity in a tracked link, it breaks, does not run, and the query element just shows the velocity code instead of the code executing.  

 

It's apparently a limitation of the email compiler to be able to run velocity and within the tracked URL, then generate the tracked link. I was disappointed. 

 

#set( $delim = ":|-" )
#set( $values = $mktmail.xMarketoIdHdr.split($delim) )
#set( $assetId = $values[7] )
${assetId}

 

Caleb_Kelly
Level 2

Re: Using {{program.id}} inside velocity?

Hi @SanfordWhiteman -  in your reply, you mention:


There’s actually yet another way to do it, but it’s even more experimental so don’t want to go there now.




Are you able to elaborate more on this? I'm curious about your experimental workaround. 🙂

SanfordWhiteman
Level 10 - Community Moderator

Re: Using {{program.id}} inside velocity?





Are you able to elaborate more on this? I'm curious about your experimental workaround. 🙂


I can’t describe it here — yet — because the risks are high if you use it wrong and it needs a whole blog post. But think about #define and you’ll eventually figure it out.

Caleb_Kelly
Level 2

Re: Using {{program.id}} inside velocity?

For whatever reason when we declare regular tokens in the body of the email, we are able to leverage the $program directive in velocity without having to set a velocity object in the unsubscribe box.

 

Email:

<!--{{Program.Id}} {{Program.name}} --> 

 

Velocity:

$program