ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.32k stars 382 forks source link

Handlebar Compile Issue #211

Open tapankumar opened 6 years ago

tapankumar commented 6 years ago

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