-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make {{#with}} work again with yields and contentFor #1
Comments
The problem is that when you call the yield helper with arguments, the arguments become the new data context. And there's no way to disambiguate no arguments vs parent arguments vs arguments as far as I can tell. Example: {{> yield region="footer"}} In this case, the yield component {{> yield}} In this case, the yield component |
I'm trying to figure this one out. Does it not make sense for Then potentially Is there a failing test that I can try and make go green here? |
( the first bit being similar to what |
Yeah there's probably something we can do here. Basically just ran out of time. Maybe we could also just set the data property of the yield component to undefined. Need to check but maybe that will always take the args data context out of the picture. I have the flu and my mind is a little cloudy so this could be total nonsense :) |
I added a failing test for this to the 1-inherit-data branch (shall I just pull this into dev?) I think it's basically impossible to achieve this however. Here's my logic. AFAIK:
is equivalent to (and indistinguishable from):
But we'd need to somehow distinguish between that and:
The only way I could see to do that is to check if |
I just pushed another test and a "fix" to 1-inherit-data which serves my purposes. It's very much related to the problem here. Here's the test case: https://github.com/EventedMind/blaze-layout/blob/1-inherit-data/layout-test.html#L67-L73 Can you see the issue? That html translates to:
So the data context for the yields in the layout is The solution (which is hacky) is to set the default This won't work if the Layout is called like IDK. Perhaps we just wait on MDG's solution to this problem and workaround it by using |
Yeah, I think you identified some of the issues. My thinking is to wait a bit to see how MDG ends up changing key value args. I think it's pretty clear that we need a way to disambiguate inclusion/block arguments, which are really more like constructor arguments, from data contexts. This gets even trickier when you think about compiled templates vs. js components. Currently, the key value arguments of a block helper actually become a new component in the parent tree (an anonymous UI.With component). So we don't ever know whether the parent data context was created because of key/value args or because there's a user defined component up there. For example: <template name="CompileMeBaby">
{{#Layout template="MasterLayout"}}
some content
{{/Layout}}
</template> compiles to a render function that looks something like this: return UI.With(function () {
return { template: 'MyasterLayout' };
}, UI.Block(function () {
return this.__content;
})); If key value args became a special property or an argument to our component init function or constructor, I think we'd be in business. |
Yes. That's what I figured from inspecting the component heirarchy. Thanks for explaining how it happens behind the scenes :) I see @avital literally just posted to core about it, so I take your word for it that they are very aware of the problem. I can live with putting in some |
Actually this isn't true! It compiles to something like
And We should discuss this and update BL to set a better default data context. |
Awesome. working. Please review #18 when you have a chance. |
You cannot currently use the {{#with}} block helper to set a data context for a yield region. You can only set a global data context for the layout using layout.data({}); This is obviously no bueno.
The text was updated successfully, but these errors were encountered: