0
votes

I'm new to Meteor, I could not find a sufficient answer to this but how does one go about referencing a Template's event handlers programmatically.

For example I would like to add or update or trigger an event defined in a template without actually as an example (pressing or clicking a button).

In the Template object I can see the events object below and can I access it but is this the right way?

Template.myTemplate._tmpl_data.events[]

Thanks!

1

1 Answers

1
votes

You can define the handler outside the event map and call it as a function:

someHandler = function(this, evt,tpl) {
  // do something with this, evt, and tpl
}

Template.myTemplate.events({
  'click .myButton': function(event,template) {
    var self = this;
    return someHandler(self, event,template);
  }
});

// Call someHandler whereever you want passing in whichever args you want

This is not a complete example, but should be able to get you going on some workable direction. If it works, please edit this answer to reflect a more complete example.