Skip to content

Template Engines

The object is used for processing of templates

Basic Usage

var response = require("http/v4/response");
var templateEngines = require("platform/v4/template-engines");

var template = 
    "Dear ${name},\n\n"
    + "You have the following bills:\n"
    + "#foreach($next in $bills)"
    + "- ${next.name}: ${next.currencySymbol}${next.value}\n"
    + "#end";

var parameters = {
    name: "John Doe",
    bills: [{
        name: "Electricity",
        currencySymbol: "$",
        value: 150
    }, {
        name: "Cable & Internet",
        currencySymbol: "$",
        value: 80
    }, {
        name: "Phone",
        currencySymbol: "$",
        value: 35
    }]
};

var result = templateEngines.generate(template, parameters);

response.println(result);

Functions


Function Description Returns
generate(template, parameters) Returns the result of the generation string
generateFromFile(location, parameters) Returns the result of the generation string
getDefaultEngine() Returns the default template engine TemplateEngine
getMustacheEngine() Returns the Mustache template engine TemplateEngine
getVelocityEngine() Returns the Velocity template engine TemplateEngine
getJavascriptEngine() Returns the Javascript template engine TemplateEngine

Objects

TemplateEngine


Function Description Returns
generate(template, parameters) Returns the result of the generation string
setSm(sm) (mustache only) Sets the expression start symbol, default is {{ -
setEm(em) (mustache only) Sets the expression end symbol, default is }} -