Email template variables

Both subject and message content support NVelocity syntax. This allows you to substitute dynamic information in your email messages when they are generated.

 

Variable Substitution

 

Standard Syntax: ${variable_name}

Example: Hello ${customer.FirstName}!

 

Shortcut Syntax: $variable_name

Example: Your serial number for $product.Name is $license.SerialNumber.

 

Shortcut syntax cannot be used if your variable is part of a larger string where the variable name would not be clear. Below shows an example of incorrect use of the shortcut syntax, where standard syntax must be used instead:

 

Incorrect (Shortcut): some_text$variable_namesome_more_text

Correct (Standard): some_text${variable_name}some_more_text

 

Standard Variables

 

Most email templates will also provide you access to the "customer" variable. This gives you access to all of the properties of the Customer object, initialized for the applicable customer.

 

Email templates that are triggered by license events will also provide access to the "license" variable. This gives you access to all the properties of the License object, initialized for the applicable license.

 

.NET Syntax and Variable Formatting

 

When you reference variables you are accessing the object through the .NET framework. You can use traditional .NET syntax to access properties and methods. A common example might be to provide string formats:

 

$license.CreatedDate.ToString("mm-ddd-yyyy")

$license.SerialNumber.ToString("")

 

Conditional Statements

 

You can employ conditional logic in your email templates with the if-else-end statement. For example:

 

#if($license.Properties["orderTotal"] > 100)

   Because your order was more than $100, we will include a free hat as a thank you.

#else

   Spend $100 or more on your next order to receive a free gift!

#end

 

Looping

 

You can loop over collections of items with the foreach-end statement. For example:

 

<table>

#foreach($item in $product.Versions)

<tr>

<td>$item.Name</td>

</tr>

#end

</table>

 

Fancy Looping

 

The foreach statement supports additional features to enable things like alternating rows, headers, and footers.

 

#foreach($i in $items)

#each (this is optional since its the default section)

      text which appears for each item

#before

      text which appears before each item

#after

      text which appears after each item

#between

      text which appears between each two items

#odd

      text which appears for every other item, including the first

#even

      text which appears for every other item, starting with the second

#nodata

      Content rendered if $items evaluated to null or empty

#beforeall

      text which appears before the loop, only if there are items

      matching condition

#afterall

      text which appears after the loop, only of there are items

      matching condition

#end