Template
These functions generate output from templates. Each function looks up a template by name and processes it through the configured renderer, substituting global variables from the script.
All the described functions take one to three parameters:
- template name (mandatory)
- language (optional) - e.g. "en-US"
- timezone (optional) - e.g. "Europa/Berlin"
The language and timezone parameters are relevant for templates that use the Comment-style renderer: when formatting dates, times and numbers, the language and timezone are used to determine the correct format, provided that the template itself does not indicate a specific format to use.
bodyFromTemplate
Generates a mail body from the HTML body of a template.
Returns { html } — an object with an html property containing the rendered HTML string.
let result = bodyFromTemplate(template_name, [language], [timezone]);
See also: subjectFromTemplate
Example 1:
let body = bodyFromTemplate("templateName");
// body.html contains the rendered HTML
Example 2:
let body = bodyFromTemplate("templateName", "en-US", "Europa/Berlin");
bodyFromTemplateText
Generates a mail body from the text body of a template.
Returns { text } — an object with a text property containing the rendered text string.
let result = bodyFromTemplateText(template_name, [language], [timezone]);
See also: subjectFromTemplate
Example:
let body = bodyFromTemplateText("templateName");
// body.text contains the rendered text
createTemplateHTML
Generates an HTML string from the HTML body of a template.
Returns a string containing the rendered HTML.
let result = createTemplateHTML(template_name, [language], [timezone]);
See also: createTemplateText
Example:
let html = createTemplateHTML("templateName");
createTemplateHTMLMail
Generates a complete mail object from a template, using the template's subject and HTML body.
Returns { subject, body: { html } }.
let result = createTemplateHTMLMail(template_name, [language], [timezone]);
See also: createTemplateTextMail
Example:
let mailData = createTemplateHTMLMail("templateName");
mailData.to = "recipient@example.com";
sendMail(mailData);
createTemplateText
Generates a text string from the text body of a template.
Returns a string containing the rendered text.
let result = createTemplateText(template_name, [language], [timezone]);
See also: createTemplateHTML
Example:
let text = createTemplateText("templateName");
createTemplateTextMail
Generates a complete mail object from a template, using the template's subject and text body.
Returns { subject, body: { text } }.
let result = createTemplateTextMail(template_name, [language], [timezone]);
See also: createTemplateHTMLMail
Example:
let mailData = createTemplateTextMail("templateName");
mailData.to = "recipient@example.com";
sendMail(mailData);
subjectFromTemplate
Generates a text string from the subject part of a template.
Returns a string containing the rendered subject.
let result = subjectFromTemplate(template_name, [language], [timezone]);
See also: bodyFromTemplate
Example:
let subject = subjectFromTemplate("templateName");
textFromTemplate
Alias for createTemplateText. Generates a text string from the text body of a template.
Returns a string containing the rendered text.
let result = textFromTemplate(template_name, [language], [timezone]);
See also: subjectFromTemplate
Example:
let text = textFromTemplate("templateName");