Open geekyme opened 11 years ago
I provided a live-demo in my tutorial app to further explain the above code: http://superman.meteor.com/parent
Click around the links 'parent', 'child', 'child2'. You will notice child2 correctly inserts content 4 if you arrive from the /parent link. But if you refresh on the link http://superman.meteor.com/parent/child2 you will see the template did not inherit anything.
@geekyme -- can you achieve what you want using controller inheritance?
ChildController = RouteController.extend({
template: 'parent',
yieldTemplates: {
'child': {to: 'parent-space1'},
'content3': {to: 'child-space2'}
}
);
Child2Controller = ChildController.extend({
yieldTemplates: {
'content4': {to: 'child-space1'}
}
});
I'm probably missing something (and might have the syntax wrong), but it seems conceptually this should achieve what you are trying (unless I'm misunderstanding you).
I just tried your suggestion. The child controller doesnt inherit the yieldTemplates from its parents. Rather, it overwrites them completely.
So in the above code, the parent...
yieldTemplates: { 'child': {to: 'parent-space1'}, 'content3': {to: 'child-space2'} }
is replaced with ...
yieldTemplates: { 'content4': {to: 'child-space1'} }
Damn.
I'm not sure how common this use case is but if we want to support it, I'd suggest that the syntax should be:
Child2Controller = ChildController.extend({
'yieldTemplates.content4': {to: 'child-space1'}
});
So it's clear when we are completely overriding and when we are just changing a single bit.
yep that syntax looks great. hoping this can be supported. Is Iron-Router currently re-rendering all templates for every route handler? Meaning from "parent" to "child" above, does it re-render the "parent" template? Or does it just insert the child template direct into the parent?
edit: accidentally clicked the close button
My understanding is that it does not re-render the template if it doesn't have to.
This is to avoid flicker that shouldn't be a problem once the UI branch of Meteor is released so the behaviour may change.
Maybe keep this bug open until we have decision on the syntax I referenced above.
Sure, in the mean time i'll just have to be more verbose in my code :)
@geekyme, Thanks for the suggestion! Will take a deeper look and mark this as design.
May I ask will this feature be pursued ?
Hi guys, I'm come from angularjs background and I've actually been using angular-ui-router for a while and I like their concept of child & parent states, with each state having layout and templates. Their sample is here - http://angular-ui.github.io/ui-router/sample/#/
In the sample above, the child auto inherits templates from the parent without the need to repeat code. It can optionally render additional templates into the parent's layout.
I've tried to apply the same concept in iron-router below, but unlike angular-ui-router, I would have to repeat myself if I want such template inheritance.
Here's what I'm doing, I might be doing it wrongly. If so please correct me: My templates -
My Router code, annotated with comments of what i'm trying to accomplish:
Any chance such template inheritance of child-parent states could be implemented in iron-router?