How to create a global function in template

How to create a function for all the templates?

Index.js

// Some function
function somefunction(){
  return true;
}

Test1.js

Template.Test1.events({
  'click button' : function (event, template){
    //call somefunction
  }
});

Test2.js

Template.Test2.events({
  'click button' : function (event, template){
    //call some function
  }
});

Index.js

// Some function
somefunction = function(){
  return true;
}

Test1.js

Template.Test1.events({
  'click button' : function (event, template){
    somefunction();
  }
});

Test2.js

Template.Test2.events({
  'click button' : function (event, template){
    somefunction();
  }
});

You might also want to check aldeed:template-extension.

3 Likes

Thanks @Steve it works :slight_smile: