Velocity Script not printing working hyperlink | Community
Skip to main content
New Participant
October 10, 2022
Solved

Velocity Script not printing working hyperlink

  • October 10, 2022
  • 2 replies
  • 2008 views

I am having an issue with the following code:

 

 

##set the variable referrer to the last Marketo Form URL and set to lowercase #set( $referrer = ${lead.anyvalue.toLowerCase()}) ##check value #if( $referrer.contains("abc")) #set( $url = "www.abc.com") #set( $name = "abc") ##second check #elseif( $referrer.contains("xyz")) #set( $url = "www.xyz.com") #set( $name ="xyz") ##fallback #else #set( $url = "www.foo.com") #set( $name ="foo") #end ##print Outcome <a href="https://$url">$name</a>

 

 

 

So the code works in basis.

The $name variable works and displays as expected in all cases. The url doesn't work. But only doens't work for the dependent values, the fallback value always shows.

 

After some testing, I found that if I take the $url out of the href tag and paste them as seperate lines, it works just fine. But, whenever I try to add it to the href tag, it breaks. The output is like this on the URL:

https://%24url/?mkt_tok=tokenhere

 

Hope anyone can help me out on this because it's driving me nuts. Looking at the documentation (and forum) this should work but clearly doesn't.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Michael_Florin-2

Have you tried using formal notation? Looking at my script library, I believe that's what Sanford taught us all to do. 🙂

<a href="https://${OutputURL}">Click here</a>



2 replies

SanfordWhiteman
New Participant
October 10, 2022

What Michael said. But also your first line should be using simple notation:

#set( $referrer = $lead.anyvalue.toLowerCase() )

 

Use simple notation when calling methods. Use formal notation when creating output or interpolating strings.

Michael_Florin-2
Michael_Florin-2Accepted solution
New Participant
October 10, 2022

Have you tried using formal notation? Looking at my script library, I believe that's what Sanford taught us all to do. 🙂

<a href="https://${OutputURL}">Click here</a>



New Participant
October 11, 2022

Thanks to both. This works like a charm!