Moe-js v0.3

Compiling Templates

Before executing a template, you must first compile it.

// Import moe
const moe = require('@toptensoftware/moe-js');

// Compile a template from a string
let template = moe.compile("<h1>{{model.title}}</h1>");

Or compile from a file (the template will be cached so subsequent calls will re-use the same template)

moe.compileFile("myTemplate.moe", "UTF8", function(err, template) {

});

Or, do it synchronously

let template = moe.compileFileSync("mytemplate.moe", "UTF8");

Or, using async/await:

let template = await moe.compileFileAsync("mytemplate.moe", "UTF8");

Once you have a template, you can execute it:

let html = template({ name: "Hello, from Moe-js"});
assert(html == "<h1>Hello, from Moe-js</h1>")