voidale:helpers-everywhere
A simple, package to make it easy use template helpers at template events, onCreated, onRendered, onDestroyed or even plain JavaScript code.
- Finds global helpers registered using "Template.registerHelper"
- Finds template instance helpers "Template.ANY.helpers({})"
helperName: string
template (optional): template instance object or a template name string.
returns: helper function, so you can use .call(), .apply(), .bind() as you need it.
Global Registered Helper:
Template.registerHelpers("demoHelper", function () {
console.log('hello');
});
Use anywhere (notice the "()" at the end required to execute the function) Can also use .call()...
Meteor.helpers("demoHelper")();
Template Instance Helpers
Template.ANY.helpers({
demoHelper: function () {
console.log('hello');
}
});
Template.ANY.onRendered({
var helper = Meteor.helpers("demoHelper", this)();
});