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

Change {{#with obj}} to not render if obj is falsey #1856

Closed
martypdx opened this issue Mar 21, 2015 · 10 comments
Closed

Change {{#with obj}} to not render if obj is falsey #1856

martypdx opened this issue Mar 21, 2015 · 10 comments

Comments

@martypdx
Copy link
Contributor

@Rich-Harris brought this up in a comment here and I agree that {{#with obj}} should not render if obj is falsey.

@Madgvox
Copy link
Member

Madgvox commented Mar 21, 2015

Shouldn't it also have the ability for an {{else}} block in that case, just like {{#each}}?

@martypdx
Copy link
Contributor Author

It does already, added it last release. :) I

t's just kind of weird in that else works when falsey, but if you don't have an else block it runs the with with the empty object. Another reason to fix it up.

@Madgvox
Copy link
Member

Madgvox commented Mar 21, 2015

Oh, sweet! I totally missed that addition. Time to go edit some templates...

@ISNIT0
Copy link
Member

ISNIT0 commented Jun 2, 2015

#1984

@Madgvox
Copy link
Member

Madgvox commented Oct 26, 2015

This behavior still occurs in 0.8-edge: http://jsfiddle.net/jwk54ah9/1/

@skeptic35
Copy link

So... am I reading too much into this or does it mean the answer to #2024 should be "an empty object ist falsey"?

@MartinKolarik
Copy link
Member

@skeptic35 yes, for explicit {{#with object}} it's now falsey. For {{#object}}, it's still truthy, but I think we should change that as well.

@dagnelies
Copy link
Contributor

dagnelies commented Oct 31, 2016

Damn, I'm always sooo late. I know it's long past, and I don't expect it to change, just wanted to add my grain of salt.

IMHO making #with work similar to #if was a step backwards.

  1. It broke all templates when upgrading from 07 to 0.8
  2. It behaves now differently than handlebars, which is counter-intuitive to many
  3. Before, a "conditional "with" could easily be achieved by combining "#if" and "#with". Now, chunks like:
{{#with just_let_the_user_fill_this_object}}
<div>
  Foo: <input value="{{.foo}}" />
  Bar: <input value="{{.bar}}" />
  More: <input value="{{.more}}" />
</div>
{{/with}}

Must always now be written more verbosely:

<div>
  Foo: <input value="{{just_let_the_user_fill_this_object.foo}}" />
  Bar: <input value="{{just_let_the_user_fill_this_object.bar}}" />
  More: <input value="{{just_let_the_user_fill_this_object.more}}" />
</div>

@evs-chris
Copy link
Contributor

@dagnelies I'm right there with you. I was using something like that in a few places too, and I think an empty object not being used as context is actually a regression. I think it should still act like an if for js falsey values, but empty arrays and objects are legitimate contexts. I shall put together a PR against 0.8 for any further discussion.

@paulocoghi
Copy link

paulocoghi commented Oct 31, 2016

I think it should still act like an if for js falsey values, but empty arrays and objects are legitimate contexts.

I totally agree, because I also had problems with this.

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

No branches or pull requests

8 participants