Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event handler for all templates?

Tags:

meteor

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.

like image 953
Marcus Riemer Avatar asked Dec 16 '22 15:12

Marcus Riemer


1 Answers

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
}
like image 87
Rahul Avatar answered Jan 14 '23 14:01

Rahul