In Meteor, I'm sending two objects from my db to a template:
Template.myTemplate.helpers({
helper1: function() {
var object1 = this; // data context set in iron:router...path is context dependent
// modify some values in object1
return this;
},
helper2: function() {
return Collection2.find({_id: this.object2_id});
}
});
This template also has an event handler to modify the two objects above. I am trying to access helper1 and helper2 from above, but if I call the data context of the template, I only get access to the unmodified version of object1. How do I access the helpers defined above?
Template.myTemplate.events({
'submit form': function(event) {
event.preventDefault();
// Access helper2 object and attributes here instead of calling Collection2.find() again
}
});
this
in the helpers you call this way, and I guessTemplate.instance()
won't work neither, unless you do some more public API violations. – SalvationTemplate.myTemplate.__helpers.get('helper');
is way too hacky, and can get obsolete at any moment in the future. Blaze is not designed to be used this way ... check my answer below – Alliteration