express-handlebars icon indicating copy to clipboard operation
express-handlebars copied to clipboard

Handlebar Compile Issue

Open tapankumar opened this issue 7 years ago • 0 comments

Hi,

I am generating dynamic html from database where in any widget (Small HTML) can be injected to any page via CMS.

I am trying to compile dynamic string via "hbs.handlebars.compile" however getting "500 Error: The partial main could not be found". "main.handlebars" is already available in views/partials as well as views/layouts however no help.

Code:

var exphbs = require('express-handlebars');
var hbs = exphbs.create({
});

//Test
router.get('/tapan', function (req, res, next) {
    var context = { message: 'Hello World!!!' };
    //var template = hbs.handlebars.compile("<p>ECHO: {{message}}</p>"); //--Working
    var template = hbs.handlebars.compile("{{> main}}"); //-- Not working
    var result = template(context);
    res.status(200).send(result);
});

What could be the issue? Is it possible to compile dynamic view with handlebars?

BR Tapan Thapa

tapankumar avatar Jul 12 '17 11:07 tapankumar