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

The "if" block helper shouldn't treat empty arrays as truthy #66

Merged
merged 1 commit into from Jun 27, 2011

Conversation

Projects
None yet
@rgrove
Contributor

rgrove commented Apr 21, 2011

Given the data {foo: []}, the following template previously considered foo to be truthy when it shouldn't have:

{{#if foo}}
  You should not see me!
{{else}}
  You should see me!
{{/if}}
The "if" block helper shouldn't treat empty arrays as truthy.
Given the data {foo: []}, the following template previously considered
foo to be truthy when it shouldn't have:

    {{#if foo}}
      You should not see me!
    {{else}}
      You should see me!
    {{/if}}
@fesplugas

This comment has been minimized.

Show comment
Hide comment
@fesplugas

fesplugas commented May 4, 2011

+1

@dougalcorn

This comment has been minimized.

Show comment
Hide comment
@dougalcorn

dougalcorn May 5, 2011

+1

The patch from rgrove looks good to me.

dougalcorn commented May 5, 2011

+1

The patch from rgrove looks good to me.

@omricohen

This comment has been minimized.

Show comment
Hide comment
@omricohen

omricohen May 14, 2011

+1
looks good to me too

omricohen commented May 14, 2011

+1
looks good to me too

@tedpennings

This comment has been minimized.

Show comment
Hide comment
@tedpennings

tedpennings commented Jun 7, 2011

+1

@pselden

This comment has been minimized.

Show comment
Hide comment
@pselden

pselden commented Jun 8, 2011

++1

@tedpennings

This comment has been minimized.

Show comment
Hide comment
@tedpennings

tedpennings Jun 20, 2011

Is there any chance this can be reviewed this month?

tedpennings commented Jun 20, 2011

Is there any chance this can be reviewed this month?

commondream added a commit that referenced this pull request Jun 27, 2011

Merge pull request #66 from rgrove/fix-empty-array-if
The "if" block helper shouldn't treat empty arrays as truthy

@commondream commondream merged commit 37e36bf into wycats:master Jun 27, 2011

@commondream

This comment has been minimized.

Show comment
Hide comment
@commondream

commondream Jun 27, 2011

Contributor

Thanks so much for the commit! Sorry for the delays here - I've been completely overloaded lately.

Contributor

commondream commented Jun 27, 2011

Thanks so much for the commit! Sorry for the delays here - I've been completely overloaded lately.

@michaelphines

This comment has been minimized.

Show comment
Hide comment
@michaelphines

michaelphines May 12, 2012

If this isn't the intended functionality, can you remove it from the documentation on http://handlebarsjs.com/?

michaelphines commented May 12, 2012

If this isn't the intended functionality, can you remove it from the documentation on http://handlebarsjs.com/?

@selvagsz

This comment has been minimized.

Show comment
Hide comment
@selvagsz

selvagsz Apr 6, 2014

@rgrove @commondream I'm quite interested about the reason on why the {{#if}} helper behaves differently from the javascript if statement ?

if([]) {
  console.log(true);  //logs true
} else {
  console.log(false);
}

selvagsz commented Apr 6, 2014

@rgrove @commondream I'm quite interested about the reason on why the {{#if}} helper behaves differently from the javascript if statement ?

if([]) {
  console.log(true);  //logs true
} else {
  console.log(false);
}
@stefanpenner

This comment has been minimized.

Show comment
Hide comment
@stefanpenner

stefanpenner Apr 6, 2014

Collaborator

I strongly agree with @selvagsz comment.

Collaborator

stefanpenner commented Apr 6, 2014

I strongly agree with @selvagsz comment.

@appleboy

This comment has been minimized.

Show comment
Hide comment
@appleboy

appleboy Apr 6, 2014

agree with @selvagsz comment + 1

appleboy commented Apr 6, 2014

agree with @selvagsz comment + 1

@rgrove

This comment has been minimized.

Show comment
Hide comment
@rgrove

rgrove Apr 6, 2014

Contributor

@selvagsz Empty arrays have always been considered falsy in Mustache sections (see http://mustache.github.io/mustache.5.html#Sections).

Seems inconsistent for {{#foo}} ... {{/foo}} and {{#if foo}} ... {{/if}} to behave differently, especially since the Handlebars docs say empty arrays are falsy (I don't remember if they did three years ago when I submitted this PR, but I do remember being very surprised that empty arrays weren't falsy and thinking it was an obvious bug).

Contributor

rgrove commented Apr 6, 2014

@selvagsz Empty arrays have always been considered falsy in Mustache sections (see http://mustache.github.io/mustache.5.html#Sections).

Seems inconsistent for {{#foo}} ... {{/foo}} and {{#if foo}} ... {{/if}} to behave differently, especially since the Handlebars docs say empty arrays are falsy (I don't remember if they did three years ago when I submitted this PR, but I do remember being very surprised that empty arrays weren't falsy and thinking it was an obvious bug).

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