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

Handlebars {{#if}} losing scope of var #503

Closed
stevenvachon opened this issue Oct 16, 2013 · 4 comments
Closed

Handlebars {{#if}} losing scope of var #503

stevenvachon opened this issue Oct 16, 2013 · 4 comments
Labels
Milestone

Comments

@stevenvachon
Copy link
Contributor

This issue goes back as far as 1.1.6—and possibly farther—and still exists in 2.0-pre.

Context Data

var context = {state:"bar"};

Ideal Approach

This should work in my eyes, however it renders "prefix-__!!__":

<div class="foo {{#if state}}prefix-{{state}}{{/if}}"></div>

Here are some failed variations that I tried:

<div class="foo {{#if state}}prefix-{{.}}{{/if}}"></div>
<div class="foo {{#if state}}prefix-{{../state}}{{/if}}"></div>

Unideal Approaches (that do work)

This works fine, but I'd like to use {{#if}}:

<div class="foo {{#state}}prefix-{{.}}{{/state}}"></div>

This sort of works, but it's possible to produce "prefix-":

<div class="foo prefix-{{state}}"></div>

It works fine using Handlebars.js

JSFiddle: http://jsfiddle.net/prometh/q6EPZ/

@imjoshdean
Copy link
Contributor

What browsers are you having issue with when it comes to

<div class="foo {{#if state}}prefix-{{state}}{{/if}}"></div>
<div class="foo {{#if state}}prefix-{{.}}{{/if}}"></div>

Because I am not seeing your !! issue with 2.0.0, proper. That said, maybe I'm not understanding Handlebars properly, but

{
  state: "foo"
}

with

<div class="foo {{#if state}}prefix-{{../state}}{{/if}}"></div>

doesn't seem like it should work at all, because it would be an explicit reference to the parent scope, which is non-existent.

@stevenvachon
Copy link
Contributor Author

Safari 6.0.5

And the ../ one was just a test to help find the source of the issue.

@imjoshdean
Copy link
Contributor

Do you still see the issue in this fiddle? http://jsfiddle.net/8qrKd/

@stevenvachon
Copy link
Contributor Author

Yes, sorry for the confusion. Long story short, ignore this bug report. Thank you for looking into this.

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

No branches or pull requests

2 participants