ericf / express-handlebars

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

support for custom helper tests? #149

Closed bradoyler closed 8 years ago

bradoyler commented 8 years ago

Hey @ericf I'm trying to get this setup working:

var exphbs = require('express-handlebars');
var helpers = {
  'if-test': function (context) {
    return true;
  }
};
var hbs = exphbs.create({helpers: helpers});

var source = '{{#if-test "y"}}works!{{/if-test}}';
var template = hbs.handlebars.compile(source);
var output = template();

But...I get error:

Error: Missing helper: 'if-test'

Any idea what I'm missing? Just trying to accomplish some custom helper testing.

bradoyler commented 8 years ago

of course, if I change: var source = '{{#if-test "y"}}works!{{/if-test}}'; to: var source = '{{#if "y"}}works!{{/if}}';

everything works as expected. So I'm not sure why the helper being passed thru the create() isn't registering the custom helper.

bradoyler commented 8 years ago

@ericf Ah, I just had to add the line:

hbs.handlebars.helpers = helpers;

before I ran compile.