wilton.js  v202103141
 All Namespaces Functions
Functions
mustache Namespace Reference

wilton/mustache
Render mustache templates. More...

Functions

String render (String template, Object|Undefined values, Function|Undefined callback)
 Render template specified as a string.
String renderFile (String templateFile, Object|Undefined values, Function|Undefined callback)
 Render template specified as a path to file.

Detailed Description

This module allows to render mustache templates from in-memory strings or directly from files.

Usage example:

// render string template
var rendered = mustache.render("{{#names}}Hi {{name}}!\n{{/names}}", {
names: [
{name: "Chris"},
{name: "Mark"},
{name: "Scott"}
]
});
// rendered == "Hi Chris!\nHi Mark!\nHi Scott!\n"
// render template from file
var resp = mustache.renderFile("path/to/my.mustache", {
foo: "bar",
baz: 42
});

Function Documentation

String mustache::render ( String  template,
Object|Undefined  values,
Function|Undefined  callback 
)

Renders template specified as a string.

Parameters
templateString template body
valuesObject|Undefined template parameters to use
callbackFunction|Undefined callback to receive result or error
Returns
String rendered template
String mustache::renderFile ( String  templateFile,
Object|Undefined  values,
Function|Undefined  callback 
)

Renders template specified as a path to file.

Parameters
templateFileString path to template file
valuesObject|Undefined template parameters to use
callbackFunction|Undefined callback to receive result or error
Returns
String rendered template