Frage

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?

War es hilfreich?

Lösung

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.

Andere Tipps

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' : '';
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top