Examples
Below you can find a set of demonstrative email scripting examples.
List of Events
This example uses a hypothetical Event custom object.
##declare an $EventsThisYear variable
#set($EventsThisYear = 0)
<table border="1">
<tr>
<th>Event Name</th><th>City</th><th>Date</th>
</tr>
##begin looping through EventsList
#foreach($event in $EventsList)
##split the date field on '-'
##yyyy-MM-dd becomes ['yyyy','MM','dd']
##retrieve first array element, the year
#set ($year = ${event.date.split("-").get(0)})
##check if $year matches designated year
#if($year == "2013")
##increment $EventsThisYear
#set($EventsThisYear = $EventsThisYear + 1)
##create info table row
<tr>
##add Event link
#set($eventUrl = "www.example.com/?event=${event.id}")
<td><a href="http://${eventUrl}">$event.name</a>
##add Event location
<td>$event.location</td>
##output formatted date
<td>$date.format('MMMM d YYYY', ${convert.parseDate($event.date, 'yyyy-MM-dd')})</td>
</tr>
##end if statement
#end
##close the loop
#end
</table>
##print out total events
Total Events ${lead.FirstName} attended this Year: $EventsThisYear
Formatting a Date
##create a date and parse it with a format
##parseDate takes two args, a date string and the format
#set($myDate = $convert.parseDate("08-07-2015", "MM-dd-yyyy"))
##format the date
##format takes two args, the format and a date object
#set($formattedDate = $date.format("yyyy-MM-dd", $myDate))
${formattedDate}
Escape a String Which May be HTML Unsafe
##escape a string which may have HTML content
#set($HTMLSafeString = $esc.html(${SurveyList.get(0).Question}))
<div>
<p><strong>In your survey, you asked:</strong></p>
<p>${HTMLSafeString}</p>
</div>
Append an ID to a URL
Batch Campaign
##batch campaigns/triggers campaigns not triggers by object
##retrieves first entry from MyCustomObjectList
##then gets objectId from record and sets it as value of $objectId
#set($objectId = MyCustomObjectList.get(0).objectId)
#set($url1 = "www.example.com/objects?id=$!{objectId}")
<a href="//${url1}">View Your Object Record Online</a>
Trigger Campaign
##trigger campaigns triggered by the needed object
##gets objectId from record and sets it as value of $objectId
#set($objectId = $TriggerObject.objectId)
#set($url2 = "www.example.com/objects?id=$!{objectId}")
<a href="//${url2}">View Your Object Record Online</a>
recommendation-more-help
bb269a6d-047a-4bf7-9acd-23ad9a63dc59