ericf / express-handlebars

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

Is there a way to use the assemble handlebar helpers #139

Open ghosh opened 9 years ago

ghosh commented 9 years ago

I am talking about this library specifically - https://github.com/assemble/handlebars-helpers

I tried something like this, could not get it to work.

app.engine('.hbs', exphbs({
    helpers: require('handlebars-helpers');
}));

Alternatively how can I use express-handlebars to render markdown content?

Sorry, I'm new to node, still figuring things out.

dinglidingli commented 9 years ago

Not sure if I'm late to the party, but you can do the following:

var exhbs = require("express-handlebars"),
    handlebarsConfig = { ... };

hbs = exhbs.create(handlebarsConfig);
require("handlebars-helpers").register(hbs.handlebars, {});

app.engine(".hbs", hbs.engine);

I hope this helps.

rsteckler commented 8 years ago

Wish I would have seen your comment before I spent an hour figuring out that hbs.handlebars is the instance to pass into handlebars-helpers.

I've now run into another incompatibility. It looks like hbs.handlebars.partials isn't populated by express-handlebars. I'm guessing this is for performance reasons, or dev/prod differentiation? In any case, handlebars-helpers tries to reference that collection for {{#extend}}, which is empty.

Linking the issues on the repos: https://github.com/assemble/handlebars-helpers/issues/205#issuecomment-174327705

Here's a quick snippet showing the issue:

hbs.getPartials().then(function (partials) {
    console.log(partials);
    console.log(hbs.handlebars.partials);
    // Outputs:
    // => { 'foo/bar': [Function], title: [Function] }
    // => {}
});