How to create a global function in template


#1

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
  }
});

#2

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

Thanks @Steve it works :slight_smile: