[solved] Adding events handlers to template dynamically in helpers

Hi everyone,
for some reason, i need to add an event handler to a template through an helper. Is it even possible ?
To complicate things, the event handler “key” should be dynamically generated.
I have tried this:

    Template.foo.helpers({
      setter : function(id){
        var instance = Template.instance();
        var key = "click " + "#" + id;
        var eventsMap = {};
        eventsMap[key] = function(){
          //doStuff....
        }
        instance.events(eventsMap);
      }
    });

The problem is that it doesn’t work.
The instance variable doesn’t have any “events” method.
Is there a solution ?
Thanks in advance.

Without going too far into the code, my first observation is that you should have

var instance = Template.instance();

(i.e. “=” not “:”)

Yeah, that’s a typo, the example i wrote here is not the actual code.

The Blaze.Template object has the events method. You should call Template.foo.events(eventsMap) instead of Template.instance().events(eventsMap).

Thank you Gwendal, i was trying something too complicated.