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

Comments

Projects
None yet
2 participants
@stevenvachon
Contributor

stevenvachon commented Oct 16, 2013

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

This comment has been minimized.

Show comment
Hide comment
@imjoshdean

imjoshdean Oct 23, 2013

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.

Contributor

imjoshdean commented Oct 23, 2013

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

This comment has been minimized.

Show comment
Hide comment
@stevenvachon

stevenvachon Oct 23, 2013

Contributor

Safari 6.0.5

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

Contributor

stevenvachon commented Oct 23, 2013

Safari 6.0.5

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

@imjoshdean

This comment has been minimized.

Show comment
Hide comment
@imjoshdean

imjoshdean Oct 23, 2013

Contributor

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

Contributor

imjoshdean commented Oct 23, 2013

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

@stevenvachon

This comment has been minimized.

Show comment
Hide comment
@stevenvachon

stevenvachon Oct 23, 2013

Contributor

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

Contributor

stevenvachon commented Oct 23, 2013

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