Created
May 13, 2015 17:29
-
-
Save AlexFrazer/0a84597f99f49b8183c2 to your computer and use it in GitHub Desktop.
Extending data with iron:router controllers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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