Marcus Riemer
Marcus Riemer

Reputation: 7728

Event handler for all templates?

I would like to install a event handler to handle all <a class="nav" /> links. Currently I am providing the same entry for event maps in almost every template. So I get entries like

Template.XXX.events = { 
  'click a.nav'          : linkCallback
}

all over the place. Is there a way to install event handlers globally? I couldn't find a way when looking at the documentation, but tmeasdays meteor-router seems to be able to do it. I just cant figure out how.

Upvotes: 4

Views: 913

Answers (1)

Rahul
Rahul

Reputation: 12231

Just make a template that wraps every other template and attach the events to it:

<body>
  {{> body}}
</body>

<template name="body">
</template>

Template.body.events = function() {
  'click .nav': linkCallback
}

Upvotes: 12

Related Questions