SOLVED

Re: Hyperlink in Velocity Script Not Working

Go to solution
Chrystal_Martin
Level 1

Hyperlink in Velocity Script Not Working

I have the following token velocity script to insert a bulleted list of up to 4 hyperlinked recommended courses in our emails:

#set($url1 = ${lead.recCourse1PURL})
#set($url2 = ${lead.recCourse2PURL})
#set($url3 = ${lead.recCourse3PURL})
#set($url4 = ${lead.recCourse4PURL})

<ul style="padding-bottom:0px; margin-bottom:0px; font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size:18px; line-height:26px;">
<li><a style="color:#2774ae; text-decoration:none; font-weight:bold;" href="${url1}">${lead.recCourse1PTitle}</a></li>

#if( !$lead.recCourse2PTitle.isEmpty() )
<li><a style="color:#2774ae; text-decoration:none; font-weight:bold;" href="${url2}">${lead.recCourse2PTitle}</a></li>
#end
#if( !$lead.recCourse3PTitle.isEmpty() )
<li><a style="color:#2774ae; text-decoration:none; font-weight:bold;" href="${url3}">${lead.recCourse3PTitle}</a></li>
#end

#if( !$lead.recCourse4PTitle.isEmpty() )
<li><a style="color:#2774ae; text-decoration:none; font-weight:bold;" href="${url4}">${lead.recCourse4PTitle}</a></li>
#end
</ul>

It displays as hyperlinked unordered list based on custom fields on the lead, looking like:

  • Introduction to Management
  • Storytelling
  • Graphic Design
  • Principles of accounting

And it works...except the second bullet's hyperlink (recCourse2PURL) never works, even when tested with several different leads. The test email always sets that link as

<li>

<a style="color:#2774ae; text-decoration:none; font-weight:bold;" href="${lead.recCourse2PURL}">Storytelling</a>.

</li>

The URL is written correctly in the field, and I've tested multiple users. Whether they only have 1 recommended course, 2, 3, or 4, the second bullet's hyperlink never works. I've triple checked that Rec Course 2 P URL has been checked for the script. Can someone help me?

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Hyperlink in Velocity Script Not Working

You definitely need to read this: https://blog.teknkl.com/multiple-marketo-tracked-links-in-velocity/ 

Also, please highlight any code that you post to the Nation so it's readable. The Advanced Editor has a Syntax Highlighter. Choose Java as it's closest to Velocity.

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Hyperlink in Velocity Script Not Working

You definitely need to read this: https://blog.teknkl.com/multiple-marketo-tracked-links-in-velocity/ 

Also, please highlight any code that you post to the Nation so it's readable. The Advanced Editor has a Syntax Highlighter. Choose Java as it's closest to Velocity.

Mark_Price
Level 7

Re: Hyperlink in Velocity Script Not Working

Def. checkout Sanford's link above!  His blog has lots of hard to find velocity information. 

For the links, I would not expect any of them to work reliably unless they are formatted with the protocol before the variable: 

<a style="color:#2774ae; text-decoration:none; font-weight:bold;" href="https://${lead.recCourse2PURL}">${lead.recCourse2PTitle}</a>‍‍‍
Chrystal_Martin
Level 1

Re: Hyperlink in Velocity Script Not Working

Thank you all for the advice! The https:// is actually already included in the field.

As it turns out...there is something wrong with our database. I was going crazy, so I just dragged Rec Course 2 P URL from the sidebar into the script, and instead of coming out as ${lead.recCourse2PURL}) (fitting with all the rest), it came out as lead.recCoursePID. No idea why. But that worked and pulls in the data from the Rec Course 2 P URL field.

I'm submitting a ticket with Marketo, because that's an odd glitch...but at least my script seems to be working now. I'm going to bookmark these solutions for the future.  

Mark_Price
Level 7

Re: Hyperlink in Velocity Script Not Working

The suggestion was made assuming you are including https:// in the field. 

Marketo has a specific system behavior and if you do not follow the guidelines- the links will break in live emails but not in previews or samples.  

Here is a snippet from the docs for reference: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!-- Correct -->
#set($url = "www.example.com/${object.id}")
<a href="http://${url}">Link Text</a>
 
<!-- Correct -->
<a href="http://www.example.com/${object.id}">Link Text</a>
 
<!-- Incorrect -->
<a href="${url}">Link Text</a>
 
<!-- Incorrect -->
<a href="{{my.link}}">Link Text</a>
 
<!-- Incorrect -->
<a href="http://{{my.link}}">Link Text</a>

https://developers.marketo.com/email-scripting/

For the fieldname, it sounds like someone re-purposed a field that was originally called recCoursePID.