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

Using "../" for parent context in {{if}} helper changes context of entire block #9263

Closed
jas opened this issue Oct 2, 2014 · 5 comments
Closed

Comments

@jas
Copy link

jas commented Oct 2, 2014

Given the following template and model:

{{#with foo}}
  {{#if ../bar}}
    {{baz}}
  {{/if}}
{{/with}}
{
  foo: {
    baz: 'OK!'
  },
  bar: true,
  baz: 'Not OK!'
}

I expect the output to be OK!, but instead it is Not OK!. It appears Ember Handlebars is changing the context within the {{#if}} helper block when ../ is used to reference the parent context.

JSBins:

@stefanpenner
Copy link
Member

Not supported in ember

@fivetanley
Copy link
Member

is this something we could support? it's really nice.

@stefanpenner
Copy link
Member

@mmun r?

@mmun
Copy link
Member

mmun commented Oct 2, 2014

@fivetanley We're moving away from context changing helpers so it will have no purpose in the future. Excusing keywords, the paths foo, ../foo, ../../foo, etc. will always return the same value. (Just like when you're using {{with x as y}} and {{each x in xs}})

In theory we could support this with context changing helpers after @twokul's work on view helper context is complete, but I recommend against it. It is a code smell and block params is the Febreze.

@jas
Copy link
Author

jas commented Oct 6, 2014

@mmun Is {{with x as y}} already supported? I'm not having any luck with that currently. (JSBin: http://emberjs.jsbin.com/guroxatoyali/2/edit)

Never mind. I had x and y swapped. Updated JSBin: http://emberjs.jsbin.com/guroxatoyali/4/edit

I didn't know about this syntax. Thanks, @mmun!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants