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

Path accessor to prevent walking up the scope #645

Closed
daffl opened this Issue Jan 6, 2014 · 6 comments

Comments

Projects
None yet
4 participants
@daffl
Contributor

daffl commented Jan 6, 2014

There are some valid use cases where walking up the scope for a property lookup is not what you want. For example:

{
  title: 'CanJS school',
  children: [{
    name: 'first'
  }, {
    name: 'second',
    title: 'Second title'
  }]
}

And

{{#each children}}
  <p>{{title}}</p>
{{/each}}

Will render CanJS school as the first item. The best solution is probably prefixing the property name with a ./ accessor if you don't want it to be looked up in the parent scope:

{{#each children}}
  <p>{{./title}}</p>
{{/each}}
@stevenvachon

This comment has been minimized.

Show comment
Hide comment
@stevenvachon

stevenvachon Jan 6, 2014

Contributor

Is {{#each children}} supposed to simulate {{#children}} to begin with? I'd have thought that a {{#with children}} would be necessary.

Contributor

stevenvachon commented Jan 6, 2014

Is {{#each children}} supposed to simulate {{#children}} to begin with? I'd have thought that a {{#with children}} would be necessary.

@matthewp

This comment has been minimized.

Show comment
Hide comment
@matthewp

matthewp Jan 6, 2014

Contributor

@stevenvachon You can use either #each children or #children for arrays.

As for the issue, personally I would rather fix this issue in JavaScript rather than adding the complexity of paths to mustache.

Contributor

matthewp commented Jan 6, 2014

@stevenvachon You can use either #each children or #children for arrays.

As for the issue, personally I would rather fix this issue in JavaScript rather than adding the complexity of paths to mustache.

@savinger

This comment has been minimized.

Show comment
Hide comment
@savinger

savinger Jan 6, 2014

@matthewp Is there some straightforward way to fix this in javascript beyond renaming attributes? I have handlebars templates that I'm trying to transition to mustache right now that render something inherently recursive. So this abstract object can have one or more similar objects within it, so they all share the same attributes, but each does not necessarily have all. All that to say renaming isn't really an option.

Just hoping that may motivate the issue a bit.

savinger commented Jan 6, 2014

@matthewp Is there some straightforward way to fix this in javascript beyond renaming attributes? I have handlebars templates that I'm trying to transition to mustache right now that render something inherently recursive. So this abstract object can have one or more similar objects within it, so they all share the same attributes, but each does not necessarily have all. All that to say renaming isn't really an option.

Just hoping that may motivate the issue a bit.

@stevenvachon

This comment has been minimized.

Show comment
Hide comment
@stevenvachon

stevenvachon Jan 6, 2014

Contributor

@matthewp

Yes, but I was referring to the context change. #each and #key do behave the same in this regard, though, despite my guessing otherwise.

Also, I'm not so sure that it can be fixed in JavaScript. #each is behaving correctly by referencing its parent scope when it cannot find a variable.

Contributor

stevenvachon commented Jan 6, 2014

@matthewp

Yes, but I was referring to the context change. #each and #key do behave the same in this regard, though, despite my guessing otherwise.

Also, I'm not so sure that it can be fixed in JavaScript. #each is behaving correctly by referencing its parent scope when it cannot find a variable.

@matthewp

This comment has been minimized.

Show comment
Hide comment
@matthewp

matthewp Jan 6, 2014

Contributor

Talked this over off-issue, I wasn't aware that ../ already exists so I withdraw my objection. @savinger

Contributor

matthewp commented Jan 6, 2014

Talked this over off-issue, I wasn't aware that ../ already exists so I withdraw my objection. @savinger

@daffl

This comment has been minimized.

Show comment
Hide comment
@daffl

daffl Apr 7, 2014

Contributor

Fixed via #874

Contributor

daffl commented Apr 7, 2014

Fixed via #874

@daffl daffl closed this Apr 7, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment