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

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -