You can use the general template for the presence of a global object and your functions inside this object.
Greetings = { hello: function(name) { return "Hello "+name+" how are you?"; } }
And then you can call it inside the template helpers:
Template.GreetingsTemplate.helpers({ sayHello: function() { return Greetings.hello('Maxence'); } })
Pay attention to the order of downloading files in Meteor; first, something is loaded inside the lib folders. If you encounter problems when the Greetings object is not defined, it is because this file has not already been downloaded.
Edit: You can reuse the same template to add additional functions to different files (you can use App = App || {}, but, for example, it will cause an error in Chrome).
App = (typeof App === 'undefined')? {} : App; App.someFunction = function(){};
or even if you use underscore.js:
App = (typeof App === 'undefined')? {} : App; _.extend(App, { someFunction: function(){} });
Joao Carlos Sep 25 '15 at 12:34 2015-09-25 12:34
source share