handlebars.js - Express & res.render passing the template as string -
i perform res.render, instead of passing template file parameter this:
res.render('index.hbs', { a: 'b' });
i able pass template string that:
let template = '{{ }}' res.render(template, { a: 'b' });
the code above not working since res.render accepts file path/name. ideas how achieve this?
you can render template first
var handlebars = require('handlebars'); // set handlebars template var source = '{{ }}'; // compile template var template = handlebars.compile(source); // call template function, passing in data context var outputstring = template({ a: 'b' });
and send output client
res.send(outputstring);
Comments
Post a Comment