EDIT: This is no longer relevant in Meteor 1.0. The first syntax has been deprecated, and only the second is supported.
It seems that there are two ways to define what are apparently called helpers in Meteor:
Template.foo.helper1 = function() { ... }
Other way:
Template.foo.helpers({
helper2: function() { ... }
});
Is there any semantic or usage difference between the two? The only restriction I can see is that the first usage can't use reserved keywords. I'm wondering if the distinction arose only for historical reasons or if there is something else.
According to http://docs.meteor.com/#template_helpers they are equivalent aside from the syntax, and the Template.myTemplate.foo syntax will not work for reserved template names.
The nice thing about using a dictionary passed to Template.myTemplate.helpers is that you can reuse it across multiple templates.
var reusableHelpers = { stuff: function() { return "stuff"; } };
Template.foo.helpers( reusableHelpers );
Template.bar.helpers( reusableHelpers );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With