Reputation: 3682
I am trying to understand the differences, the pros and the cons of using Meteor Template helpers versus using Handlebars Template helpers.
For example:
Template.users_insert.is_state_selected = function(code){};
versus
Handlebars.registerHelper('is_state_selected', function(code){});
They seem to do the same thing except that the Handelbars helper has a wider of scope of coverage for us versus the Temple.my_template.helper_function
.
My big concerns are not only the differences and pros and cons but also side effects one may cause that another does not.
Upvotes: 4
Views: 2044
Reputation: 1782
One thing here is missed.
Handlebars Helpers registered with
Handlebars.registerHelper('helper_name', function(){});
are available in for the whole project.
in Meteor
Template.my_template.helpers({});
or
Template.my_template.my_helper = function(){};
are available just for the current Template: e.g. my_template
Upvotes: 3
Reputation: 7728
This is how I distinguish between these two mechanisms, no guarantee for correctness ;)
Meteor template methods are used for databinding, thats why they have local scope. Every template needs a subset of the application data, possibly represented in various forms. And this subset is defined via the template methods.
Handlebars is the templating framework itself, so the helpers control how your application will present the data it receives from the Meteor "data layer". You may want some special kinds of enumeration, need a way to "map" data values to paths etc ... But you only work with the data provided by the "data layer" and do not extend it.
Upvotes: 1