Error with simple helper #33

Closed
olalonde opened this Issue Oct 9, 2012 · 12 comments

Comments

Projects
None yet
3 participants

olalonde commented Oct 9, 2012

I'm getting a bug with that helper:

hbs.registerHelper('fromnow', function(val) {
    return 'test';
});

and in my view:

{{fromnow user}}

The error is:

/node_modules/hbs/node_modules/handlebars/lib/handlebars/base.js:22
    throw new Error("Could not find property '" + arg + "'");
          ^
Error: Could not find property 'fromnow'
Collaborator

defunctzombie commented Oct 9, 2012

Are you registering the helper before rendering the view? Can you provide a simple example showing the bug.

olalonde commented Oct 9, 2012

Yes my code flow is a bit like this:

var hbs = require('hbs');

// ...

hbs.registerHelper('fromnow', function(val) {
  return 'test';
});

// ....
app.set('views', __dirname + '/views');
app.set('view engine', 'hbs');


// ... then in some route

res.render('view', {user: {name:'aa'}});

My views work fine with the builtin helpers but my own registered helpers always throw that error :(

Collaborator

defunctzombie commented Oct 9, 2012

Can you tell me what version of hbs you have installed and what version of handlebars?

olalonde commented Oct 9, 2012

├─┬ hbs@1.0.5
│ └─┬ handlebars@1.0.5beta

olalonde commented Oct 9, 2012

also

express@3.0.0rc4

olalonde commented Oct 9, 2012

been stuck on this for almost 2 hours, do you have any idea of what might be the problem?

Collaborator

defunctzombie commented Oct 9, 2012

No, I do not. I would recommend removing anything else in the app and creating a minimal broken example with nothing extra.

olalonde commented Oct 9, 2012

Damn it, the bug was cause by this little piece of code:

if(app.get('env') != 'production') {
  // todo: make last_req available
  console.log('');
  console.log('You can now type Javascript expressions in the interactive REPL.');
  console.log('Some useful expressions:');
  console.log('app.routes');
  console.log('app.models');
  console.log('app.lastReq');
  console.log('');
  repl.start('>>> '.green);
}

I still can't figure what might be the problem here :( At least I found the bug

Just an FYI, I'm running into this now too.

Some details on my bug. Here is my app.js. You can see I'm regstering the helper (using a simple string for now in the result).

https://gist.github.com/cfjedimaster/5746567

And here is my view:

https://gist.github.com/cfjedimaster/5746569

Sorry - it must have been a typo. It is working ok now.

Heh, I see it. I called dateHelper in my view, but it was dateFormat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment