How to manage template scripting

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!";}}
    • Related Articles

    • How to create custom contact fields

      Learn more about how to use custom contact fields to store and manage more information! Each contact that you store in your VMA Emailer account contains basic information like email address and the recipient's first or last name. It is possible to ...
    • How to manage different UTM parameters

      UTM parameters are special code strings that can be appended to your links in order to track their clicks via Google Analytics. As default, each link within the template is UTM-free. Example: http://yourlink.com When UTM is enabled, each link within ...
    • How to customize a gallery template

      VMA Emailer offers a gallery of free pre-designed templates to help get you started. It is easy to customize a pre-designed template. Navigate to your Templates Screen, select the Gallery tab, and then choose from one of the pre-designed templates. ...
    • How to manage templates

      A good template can be used again and again. Become familiar with your templates screen and all that it has to offer. VMA Emailer supports both body_text and body_html in our emails. Templates in HTML can be used over and over in your emails. My ...
    • Can I customise a template to suit my needs?

      Yes, go to "Templates" then "Create a Custom Template" and you can customise it so suit your needs. You can also import a template you have created in another program, but make sure is contains valid HTML. You can also "Import a web Page" but ensure ...