blaineh
blaineh

Reputation: 2323

Use handlebars helper as function in javascript

I have a handlebars helper defined like this:

Handlebars.registerHelper('isAdmin', function(input){
    return Meteor.user() && Meteor.user().admin;
});

and I'd like to use it elsewhere in my js as if it were a normal function. Is that possible?

Upvotes: 0

Views: 1145

Answers (1)

David Weldon
David Weldon

Reputation: 64312

You could make a global function called isAdmin and then define your helper like this:

this.isAdmin = function(input) {
  return Meteor.user() && Meteor.user().admin;
};

Handlebars.registerHelper('isAdmin', isAdmin);

Then you can use it anywhere in your templates like:

Template.party.events({
  'submit': function() {
    if (isAdmin()) {
      return console.log('admin party!');
    }
  }
});

Upvotes: 2

Related Questions