This is my first time using Velocity so apologies if it's an obvious answer. We need to populate based on multiple contains values in a single field, and have a default for anything that doesn't match but I'm not sure how best to write this out using Velocity. How would I write out this script?
If Job Function contains "programmer" "engineer"
Show: "Hello techie person"
elseIf Job Function contains "marketer" "sales"
Show: "Hello marketing person"
elseIf Job Function doesn't contain any of those values
Show: "Hello general person"
Solved! Go to Solution.
#set( $imagePath = "http://lp.accessintel.com/rs/881-ZTT-725/images/" )
#set( $outputByjobFunction = [
{
"pattern" : "(?i).*\b(programmer|engineer)\b.*",
"color" : "#800080",
"greeting" : "techie person",
"images" : [
"sm-black_i_50.gif",
"sm-black_f_50.gif",
"sm-black_t_50.gif"
]
},
{
"pattern" : "(?i).*\b(marketer|sales)\b.*",
"color" : "#B1309D",
"greeting" : "marketing person",
"images" : [
"sm-rnd_fb_grey.png",
"sm-rnd_i_grey.png"
]
},
{
"pattern" : ".*",
"color" : "#99cc00",
"greeting" : "general person",
"images" : [
"sm-square_li_100.gif",
"sm-square_g_100.gif",
"sm-square_fb_100.gif",
"sm-square_t_100.gif"
]
}
] )
#foreach( $outputSet in $outputByjobFunction )
#if( $lead.jobFunction.matches($outputSet.pattern) )
#set( $matchedOutputSet = $outputSet )
#break
#end
#end
<span style="color: ${matchedOutputSet.color};">${matchedOutputSet.greeting}</span>
<table width="60%" border="0" cellspacing="0" cellpadding="6">
<tbody>
<tr>
#foreach( $image in $matchedOutputSet.images )
<td align="center"><img src="${imagePath}${image}" width="30"></td>
#end
</tr>
</tbody>
</table>
I keep wondering if it would be faster to set up individual email script tokens with the tables of each images (the team keeps complicating this with more formatting needs, size changes, adding text, links, etc)
It's almost never better to repeat yourself, though at the same time you have to stop people from constantly changing the spec on you...