SpTools Function Library
Immediately before any template is submitted for evaluation by the Velocity engine, the spTools
argument is added to the VelocityContext so the template can access its methods. SpTools is a function library that contains a few localization utility methods to help with message formatting – primarily date formatting. The methods available within spTools are listed below:
String formatDate(Object date)
Formats the passed-in date object to a string representation using the IIQ default date and time styles (both the java.util.dateformat SHORT formats), formatted per the norms of the server's default locale and timezone
String formatDate(Object date, Integer dateStyle, Integer timeStyle)
Formats the passed-in date object to a string representation using the specified date and time styles, formatted per the norms of the server's default locale and timezone
NOTE: The styles are represented by constant values:
SHORT = 3
MEDIUM = 2
LONG = 1
FULL = 0
dateStyle and timeStyle correspond to java.text.DateFormat constants. See the Sun Javadocs for details
String formatDate(Object date, String formatString)
Formats the date according to the specified formatString (uses the java.text.SimpleDateFormat method)
String getMessage(String key)
Returns an internationalized message from the message catalog corresponding to the provided key
String escapeHtml(String string)
Converts HTML special characters to their entity equivalents
Example:escapeHtml('<div class="article">This is an article</div>')
Returns: <div class="article">This is an article</div>
In the out-of-the-box email templates, the most commonly used method from this library is the formatDate()
method that takes a date object and two integers as arguments:
$spTools.formatDate($expiration,3,1)
After the reference shown above is resolved by Velocity, the date/time value in the expiration argument is printed in the email message in MM/dd/yy hh:mm:ssPM format (or the appropriate equivalent for the server's locale).