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

Is there a way to use the assemble handlebar helpers

Open ghosh opened this issue 10 years ago • 2 comments

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.

ghosh avatar Aug 12 '15 06:08 ghosh

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.

dinglidingli avatar Sep 23 '15 10:09 dinglidingli

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] }
    // => {}
});

rsteckler avatar Jan 24 '16 18:01 rsteckler