1 Reply Latest reply on Sep 15, 2016 1:28 AM by Sanford Whiteman

    Populate image with link using Velocity script

      Anyone knows why the below script fails to populate an email with an image that has a URL?

       

      <p style="text-align: center;"><a href="https://${contentUrl_1}?{{my.programUTM}}" target="_blank"><img src="${contentImageUrl_1}" alt="${contentImageText_1}" height="${contentImageHeight_1}" width="${contentImageWidth_1}" /></a><br /></p>


      If I replace the 'href' section with something else than the image appears but the link will not work as the URL is not valid (see below).

       

      <p style="text-align: center;"><a href="{{my.Content2_Link}}" target="_blank"><img src="https://${contentImageUrl_2}" alt="${contentImageText_2}" height="${contentImageHeight_2}" width="${contentImageWidth_2}" /></a><br /></p>

       

      The URL used in the first version also works if used in a text.

      href="https://${contentUrl_1}?{{my.programUTM}}"

       

      If I replace the URL with a valid but short URL (e.g. https://yahoo.com) than the link works but the image disappears (and all other velocity tokens in the same email tile also fail).

       

      Any suggestions?

        • Re: Populate image with link using Velocity script
          Sanford Whiteman

          Can't be the whole of the current script, or else you're setting vars like $contentUrl_1 in another script. Either way, we're not seeing the whole thing.

           

          At least part of the problem is that it looks like you're trying to interpolate a text {{my.token}} in the VTL context. That won't work. Depending on how you test, you may get totally borked HTML sometimes and visible-but-still-not-working links at other times. But you aren't going to get the output you want.

           

          Instead of including a text {{my.token}}, create another Velocity {{my.token}} and have it set a $variable to the UTM query string (this token it doesn't output anything at all, it only #set()s the var). Include this non-output {{my.token}} at the top of the email. Then you can Include that $variable in subsequent Velocity {{my.tokens}}.  For an example of the way variable scope is preserved ("context chaining") between Velocity tokens, see my blog post http://blog.teknkl.com/just-in-time-content-suppression-with-a-comment-token/.

           

          You'll have to provide the full HTML output/s (and the full Velocity code) for further troubleshooting.