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

{{else}} block changes the context but {{#if}} does not #754

Closed
raoulmillais opened this issue Feb 26, 2014 · 1 comment
Closed

{{else}} block changes the context but {{#if}} does not #754

raoulmillais opened this issue Feb 26, 2014 · 1 comment

Comments

@raoulmillais
Copy link

When using an {{#if}} ... {{else}} ... {{/if}} block the else block makes the context one level deeper whereas the if block does not. I have encountered this inside an each, but I'm not sure whether it is also a problem at the top level. My preference is that neither deepens the context, but either way it would be better if they were consistent.

E.g.

Given this context:

var ctx = {
  items: [{
    someValue: true, // or false
  }],
  successMessage: 'It works',
  failureMessage: 'It fails'
};

I must use this handlebars markup to render the failure message:

{{#each items}}
  {{#if someValue}}
    <h1>{{../successMessage}}</h1>
  {{else}}
  {{! need to go up another level to get to the root }}
    <h1>{{../../failureMessage}}</h1>
  {{/if}
{{/each}}
@raoulmillais
Copy link
Author

Hmmm, updating express3-handlebars has fixed the problem. Maybe it was an issue in an older version. I'll close this.

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

1 participant