Hi,
We have an email template that is triggered from an external service interacting with Marketo. The service will send some input to Marketo to set the value of certain tokens, e.g. my.City, my.SenderName, etc.. In the template we want to have a picture of the person sending the mail. All the pictures are stored in "Design studio"->"Image and Files". What we would like to do, is to retrieve and insert the right picture based on one of the tokens we are going to update.
I've looked at email scripts for a couple of days, but I don't see how I can point to the image in the template or update it's URL. Can the modules the template is made of and their components (an image for example) be referred to in some way in the script (something like moduleName.imageName.url)? And would this be the right approach?
Thank you,
Gianfranco
Solved! Go to Solution.
Hmm, that's not the way Velocity works. It doesn't manipulate the email's DOM or the object model of the email like that. It calculates HTML or Text output (which is placed in exactly the same place you put the token in the email).
Also, you can't use the $my.PictureName runtime Text {{my.token}} token from Velocity (Velocity can read from variables set in other Velocity variables, from Lead and Company fields, and from Custom Objects, but not from other non-Velocity {{my.tokens}})
However the <img> src is based directly on a runtime {{my.token}}, why not just have the src be another {{my.token}} (that you pass from the client)?
How many different people are there who's image you want to insert?
I'd guess you would want to create a number of tokens at the program level that house all the images individually and then you would havea velocity script with some type of "if else" script determining the image to insert.
Hi Gerard,
Thank you for your answer.
It will be around 18 persons. Yes, the idea was to have some tokens and then use a velocity script. But I don't get how to manipulate the URL since I haven't understood how to refer to it in the script. I'll try to test a little bit more according to yours and Sanford's combined suggestion and another example I have found.
What Gerard said -- a map between {{my.token}} values and corresponding image URLs -- or, more simply, enforce a naming convention on your files. So if gianfranco@simonetta.com is the From: address, then gianfranco_simonetta_com.png is your photo.
Thank you for the clarification, Sanford. I'll try something like that.
Regards,
Gianfranco
OK,
so... in the template draft the image I want to update is called First Module Image. I looked at the HTML code of it and the id is "firstModuleImg"
I created a new email script token my.PictureName. It looks like this and I guess it is wrong since it is not working
#if($my.PictureName == "Anna")
##update the image's URL
#set($firstModuleImg.src = "http://info.something.com/rs/626-CSV-637/images/anna.jpg")
#end
Hmm, that's not the way Velocity works. It doesn't manipulate the email's DOM or the object model of the email like that. It calculates HTML or Text output (which is placed in exactly the same place you put the token in the email).
Also, you can't use the $my.PictureName runtime Text {{my.token}} token from Velocity (Velocity can read from variables set in other Velocity variables, from Lead and Company fields, and from Custom Objects, but not from other non-Velocity {{my.tokens}})
However the <img> src is based directly on a runtime {{my.token}}, why not just have the src be another {{my.token}} (that you pass from the client)?
Hi again,
Thank you for your support, Sanford.
In the end, the solution adopt is like your last suggestion. A token my.PictureName that will be passed from our external service and will set the src in the HTML.
If anyone needs it in future, it looks simply like this in the HTML for the template:
<p> test image: <img src="{{my.PictureName}}" /> </p>
Regards,
Gianfranco
I had a similar situation, so I ended up creating this script and it worked for me, hope this is helpful - for my case we needed to populate a different image (saved in Design Studio) depending on how many boxes the customer purchased.
1. Name of my program token: my.TestImages
2. How I populated it in the email:
<p><img src="{{my.TestImages}}" height="225" width="225" /></p> or <img src="$ImgSrc" alt="" constrain="true" imagepreview="false" border="" />
3. How I set up the script (checked the {lead.boxes} in the fields to the right of the script column):
#set($Myimage = ${lead.boxes})
#if($Myimage == "40")
#set($ImgSrc = "http://go.bauschhealth.com/rs/350-OKO-721/images/Image2.jpg")
#elseif($Myimage == "80")
#set($ImgSrc = "http://go.bauschhealth.com/rs/350-OKO-721/images/Image1.png")
#end
${ImgSrc}
Hope this is of help to you. Thanks
Hi there,
When posting code, make sure to highlight it using the Advanced Editor's syntax highlighter so it's readable:
In a #set statement, you shouldn't use ${formal} notation because it doesn't support dot-method chaining, causing later syntax errors. Use $simple notation instead. Only use ${formal} for output.
So this line:
#set($Myimage = ${lead.boxes})
should be this:
#set($Myimage = $lead.boxes)
But it's easier to read and maintain if you replace your code entirely with a collection-centric approach:
#set( $imageByLeadBoxes = {
"40" : "Image2.jpg",
"80" : "Image1.png"
} )
http://go.bauschhealth.com/rs/350-OKO-721/images/${imageByLeadBoxes[$lead.boxes]}