data:
var data = {
bold: function () {
return function (text, render) {
return "<b>" + render(text) + "</b>";
}
}
}
res.writeHeader(200, {
"Content-Type": "text/html"
});
var stream = mu.compileAndRender('test.html', data);
stream.pipe(res);
html
{{#bold}}I'm Bold.{{/bold}}
My function isnt working as expected in node.js, it just outputs the text unchanged.
You could try using the client-side version, which also works in node.js:
// assuming mustache.js is in current directory
var Mustache = require('./mustache');
var data = {
bold: function () {
return function (text, render) {
return "<b>" + render(text) + "</b>";
}
}
};
console.log(Mustache.render('{{#bold}}I\'m bold.{{/bold}}', data));