First, call res.render()
by providing a callback function. Both the possible error and the rendered string are passed to this callback function. res.render()
won't perform automated response to the client side.
Second, apply require('ejs').render()
to the rendered string in the callback function.
Finally, send the result to the client side.
exports.test = function(req, res) {
var people = [{"name":"Martin"}, {"name":"Jean"}];
res.render( 'template',
{open:'<@', close:'@>', test : "Hello world"},
function(err, html) {
if (err) {
res.send(500, err);
} else {
res.send(require('ejs').render(html, {people: people}));
};
});
};