سؤال

In 0.7.2, I could have something like this

<span>{{color 'blue'}}</span>

Handlebars.registerHelper('color', function (parameter) {
   return Session.equals('color', parameter) ? 'blue' : 'red';
});

and it would work perfectly fine. What is the equivalent in the 0.8.0 release? I know they replaced Handlebars.registerHelper with UI.registerHelper, but this

UI.registerHelper('color', function (parameter) {
    return Session.equals('color', parameter) ? 'blue' : 'red';
});

still returns this error

Exception in Meteor UI: Error: Can't call non-function: [object Object]

Any help?

هل كانت مفيدة؟

المحلول

Turns out it was all because one of my registerHelpers was the word 'parent'. Using that threw an error so it made it seem like all of my helpers were messed up. I'm guessing that it's a reserved word.

نصائح أخرى

I'm doing this & it works (exactly as I use it). Do you use iron-router? This might do too.

UI.registerHelper('routeActive', function(routeName) {
var route = Router.current();

    if(route && route.route && route.route.name == routeName) return 'active';
});

Then you can use the name of your template/route in routeName

I'm a bit unsure why you're getting that error are you sure its from the Handlebars expression.

You probably need to pass the parameter with a name:

<span>{{activePath path='home'}}</span>

UI.registerHelper('activePath', function() {
  return Session.equals('activePath', this.path) ? 'active' : '';
});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top