How to manage template scripting

Check out how you can implement template scripting in your emails.

Script fields are denoted with {{ }}.

Make sure Template Scripting is enabled in your Account's Sending Settings.

Javascript can be used inside the script fields.

Script fields can be used in the subject, HTML, and text body.
**Note: due to subject field size limit, it's advised to put the main scripting in the HTML and use short expressions in the subject element.

The scripting engine also includes the Contact and Profile Merge Fields, for example {{ var myname = accountfirstname + ' ' + accountlastname; }}. Fields defined in CSV mail merge are also accessible by their column names. Note that the generic Merge Fields such as {{unsubscribe}} or {{view}} can not be used currently with Template Scripting.

Exceptions

A Javascript code error inside the script field will prevent the email from being sent and will be reported as a bounce. Standard JavaScript try/catch can be leveraged to control error handling.

Additional Functions

  • md5(text) - returns the MD5 hash of given string.
  • download(url) - downloads and returns page content as string. If remote server can't be contacted, an exception is thrown.
  • htmltag(html, tag) - returns value of a given tag, e.g. var subject = htmltag(content, 'title');

Example 1

Subject line

{{ subject }}

HTML

{{
var html = download('http://somewhere.com?recipient=' + encodeURIComponent(email)); // note: email is defined as a part of standard merge field set.
html = html.replace('[-EMAILADDR-]', email);
html = html.replace('04102014', Math.floor(Math.random() * 100000000));

var subject = htmltag(html, 'title');

htmltag(html, 'body'); // this line evaluates to content in the body tag and is returned by this script block
}}

Example 2

Subject line

Today is {{new Date()}}.

HTML

{{
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
today = yyyy + '-' + mm + '-' + dd;
null; // this line is so this script block evaluates to null, otherwise it would have evaluated to content of today variable.
}}
<p>This is a page that links to today's <a href="http://dilbert.com/strip/{{today}}">Dilbert</a> strip.</p>

Example 3

Merge fields with alternative display when you do not have data for that merge field.

For example you want to add {firstname} field that will show First Name of your recipient if you have it on file, but will show "Hi there!" if you do not have information about First Name of your recipient.

{{var greeting = "Dear " + firstname + ",";if (firstname.length==0) greeting = "Hi there!";}}
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to design emails for Outlook recipients

This article will cover some tips to help you get the best results when sending to outlook...

How to run an A/X split test

A/X split testing is a good way to test how your mail or message is doing and how your...

How to customize a gallery template

VMA Emailer offers a gallery of free pre-designed templates to help get you started. It is...

How to manage custom branded templates

Customize your customer's template gallery with your own branded templates. VMA Emailer offers...

How to manage templates

A good template can be used again and again. Become familiar with your templates screen and all...