express-handlebars
express-handlebars copied to clipboard
dynamically include a partial
I want to include a partial based on a variable I pass to the view
example:
router.get('/page', function(req, res, next) {
res.render('pages/page', {partial: 'whateverPartial'});
});
now in the view:
<h3>dont care</h3>
{{> partial}}
I browsed all over the web and found this solution, but it doesn't work. it said for placing variable instead of a string do like this
{{> (partial) }}
but it gives me this error:
Message: ((helpers.partial || (depth0 && depth0.partial)) || alias2).call is not a function
any ideas how to solve that?
router.get('/page', function(req, res, next) {
res.render('pages/page', {
partial: function () {
return 'whateverPartial'
}
});
});
When using dynamic partials, '(partial)' must be a function. See here: http://handlebarsjs.com/partials.html#dynamic-partials