Skip to content
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

Easy way to force no data context in templates #5459

Closed
mitar opened this issue Oct 18, 2015 · 12 comments
Closed

Easy way to force no data context in templates #5459

mitar opened this issue Oct 18, 2015 · 12 comments

Comments

@mitar
Copy link
Contributor

mitar commented Oct 18, 2015

Maybe one issue with Blaze is that it is hard to say that you do not want a given data context to continue. You can easily set it to something with #with, but it is unclear how to force it to no data context.

@stubailo
Copy link
Contributor

Can you give me more details and some examples of how a proposed system would work? Is it as simple as a block helper like {{#clearDataContext}}?

@mitar
Copy link
Contributor Author

mitar commented Oct 20, 2015

Hm, now that I think about, isn't this the same as {{#with null}}...{{/with}}? No data context is represented as null anyway, no?

So does {{> FooBar null}} work?

Maybe the issue then with Blaze is that default should be that {{> FooBar}} does not pass data context further, and if you want to do that, you have to pass it explicitly {{> FooBar this}}.

@stubailo
Copy link
Contributor

Yeah I think that would be a great default, but would surely break tons and tons of apps.

@mitar
Copy link
Contributor Author

mitar commented Oct 20, 2015

The solution is simple:

<template name="foo" version="2.0">
  ...
</template>

@stubailo
Copy link
Contributor

Yeah, we considered that for sure. It wouldn't be hard to make that possible with that PR for template attributes!

@mitar
Copy link
Contributor Author

mitar commented Oct 20, 2015

Exactly what I had in mind as well. :-)

@mitar
Copy link
Contributor Author

mitar commented Oct 20, 2015

Maybe an intermediate thing would be that you could somehow signal to the included template if data context was passed explicitly or was inherited. So that you could do something like templateInstance.view.wasDataContextPassed.

Because then I could implement this in Blaze Components probably. Even without arguments support in templates.

@stubailo
Copy link
Contributor

Oh, interesting. Maybe you could hackily detect if the parent view is a {{#with}} that is automatically generated?

@mitar
Copy link
Contributor Author

mitar commented Oct 21, 2015

Not sure if that is possible because for example Blaze Layout use the same code as spacebars generated code. So there is no real way to distinguish between those.

Maybe Spacebars.include should simply get another argument? And template compiler would then set it?

@mitar
Copy link
Contributor Author

mitar commented Oct 21, 2015

On the other hand, I am not sure which approach is better. I am using this approach in my app to clear the data context currently. So not sure which approach (using Blaze.Template & Blaze.With or using Blaze._TemplateWith & Spacebars.include) is better. Because of that I think various people do various things in code and it would be hard to detect that then.

@mitar
Copy link
Contributor Author

mitar commented Oct 23, 2015

Oh, in fact this together with #5095 would make wonders. :-) You could build your own custom data context any way you want.

@mitar
Copy link
Contributor Author

mitar commented Sep 25, 2016

Closing in favor of meteor/blaze#113.

@mitar mitar closed this as completed Sep 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants