SOLVED

Velocity token: traceable links fail, but work if non traceable

Go to solution
Grégoire_Miche2
Level 10

Re: Velocity token: traceable links fail, but work if non traceable

Really cool. Thx

-Greg

Grégoire_Miche2
Level 10

Re: Velocity token: traceable links fail, but work if non traceable

Hi Sanford,

Is there a way to store the dictionary outside of the Velocity script, in a place where it would be easily maintained?

-Greg

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity token: traceable links fail, but work if non traceable

You can store the variable in a separate token (which I recommend for data dicts like this) and include it in the <head> of your templates.

But you can't read directly from anywhere but the Velocity context. You can use a separate app to periodically copy data from a text file into a token, but that's creating some moving parts.  Doable, though.

Grégoire_Miche2
Level 10

Re: Velocity token: traceable links fail, but work if non traceable

Hi Sanford Whiteman ,

I have tested the code from the blog and this is the email, with  different values selected in the form:

pastedImage_1.png

It renders the 1st one 4 times

-Greg

Grégoire_Miche2
Level 10

Re: Velocity token: traceable links fail, but work if non traceable

PS: can it be because the variable velocityCountis not incremented ?

-Greg

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity token: traceable links fail, but work if non traceable

PS: can it be because the variable velocityCountis not incremented ?

$velocityCount is automatically created and incremented.

Maybe there's something different in your instance. Try $foreach.count instead of $velocityCount.

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity token: traceable links fail, but work if non traceable

... full line being

  #evaluate( "${esc.h}set( ${esc.d}downloadLink_${foreach.count} = ${esc.d}downloadLink )" )

Grégoire_Miche2
Level 10

Re: Velocity token: traceable links fail, but work if non traceable

Hi again Sanford,

My bad. If velocity count was not incremented, downloadink_2 and above would be empty.

Here, the output seems not to find any other value than the first one (downloadLink_1) and repeat it for each item.

-Greg

Grégoire_Miche2
Level 10

Re: Velocity token: traceable links fail, but work if non traceable

I tried this code:

#foreach( $key in $lead.downloadcenter.split(";") )

  #set( $downloadLink = $allDownloadLinks[$key] )

  ${downloadLink.text}</br>

  #evaluate( "${esc.h}set( ${esc.d}downloadLink_${velocityCount} = ${esc.d}downloadLink )" )

#end

and it is rendering

IV Case Study

IV Case Study

-Greg

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity token: traceable links fail, but work if non traceable

On the assumption that your instance is configured differently please try this code instead (replacing the code after the dict of course):

#foreach( $key in $lead.downloadcenter.split(";") )

  #set( $downloadLink = $allDownloadLinks[$key] )

  #evaluate( "${esc.h}set( ${esc.d}downloadLinkHref_${foreach.count} = ${esc.d}downloadLink.href )" )

  #evaluate( "${esc.h}set( ${esc.d}downloadLinkText_${foreach.count} = ${esc.d}downloadLink.text )" )

#end

#if( $downloadLinkHref_1 )

<a href="http://${downloadLinkHref_1}" target="_blank">${downloadLinkText_1}</a>

#end

#if( $downloadLinkHref_2 )

<a href="http://${downloadLinkHref_2}" target="_blank">${downloadLinkText_2}</a>

#end

#if( $downloadLinkHref_3 )

<a href="http://${downloadLinkHref_3}" target="_blank">${downloadLinkText_3}</a>

#end

#if( $downloadLinkHref_4 )

<a href="http://${downloadLinkHref_4}" target="_blank">${downloadLinkText_4}</a>

#end

#if( $downloadLinkHref_5 )

<a href="http://${downloadLinkHref_5}" target="_blank">${downloadLinkText_5}</a>

#end