node.jsexpressrailway.js

ExpressJS Get resulting source from view instead of rendering it


I'm intending to use some ejs templates to generate HTML for sending out emails.

I'd like to pass in a model to my view, and get back the resulting HTML So, instead of render() - i want to 'get' the html into a variable before it's passed back to the browser?

Is that possible?


Solution

  • Something like the following will work:

    var ejs = require('ejs');
    var str = ejs.render("<title><%= title %></title>", {title: 'Hello'});
    console.log(str);