Skip to content

Instantly share code, notes, and snippets.

@AlexFrazer
Created May 13, 2015 17:29
Show Gist options
  • Save AlexFrazer/0a84597f99f49b8183c2 to your computer and use it in GitHub Desktop.
Save AlexFrazer/0a84597f99f49b8183c2 to your computer and use it in GitHub Desktop.
Extending data with iron:router controllers
ChildController = ParentController.extend({
showItem: function () {
/**
* Here is the problem.
* I want to implicitly pass the "group" to EVERY rendered route
* Is it possible to do this?
*/
var group = ChildController.__super__.data.call();
this.render('itemPage', {
data: {
items: Items.find(),
group: group
}
});
}
});
var errorHandler = function (e) {
this.render('errorPage', {
data: e
});
this.stop();
};
/**
* Extend this controller and parse the :groupSlug into a Group
* Then pass the data down to the children controllers.
*/
ParentController = RouteController.extend({
waitOn: function () {
var subError = _.bind(errorHandler, this);
return Meteor.subscribe('group', this.params.groupSlug, {
onError: subError
});
},
data: function () {
return Groups.findOne({ slug: this.params.groupSlug });
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment