Meteor/Iron-Router - How pass values from RouteController to template helper
meteor
Solution
Use the data function in the controller
add_departmentController = RouteController.extend({
template: 'departmentTemplate',
data: function(){
return {_id: this.params._id};
}
});
This "injects" the returned object of the data function as the data-context into your template.
[EDIT]
Template: The {{_id}} comes directly from the data context, {{idFromHelper}} returns the _id from a template helper function.
<template name="departmentTemplate">
{{_id}}
{{idFromHelper}}
</template>
Helper:
Template.addDepartment.helpers({
idFromHelper: function() {
return this._id;
}
})
Problem
If I have a route controller as follows: ``` add_departmentController = RouteController.extend({ before: function(){ var a = this.params._id; var b = 'abc'; } }); ``` How can I access these values in a helper for the template ``` Template.add_department.helpers({ SomeProperty: function () { //Here I need access to a or b from above //Would also be nice to access 'this' directly eg. this.params }, }); ```