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

{{#with <value that's false> as |bar|}} block isn't rendered #1224

Closed
shawnam opened this issue May 20, 2016 · 5 comments
Closed

{{#with <value that's false> as |bar|}} block isn't rendered #1224

shawnam opened this issue May 20, 2016 · 5 comments

Comments

@shawnam
Copy link

shawnam commented May 20, 2016

Maybe this is expected. The docs didn't seem to answer this particular scenario.

I put together a fiddle here:
https://jsfiddle.net/oo3qq3nx/1/

Specifically, I was expecting

{{#with asetting as |bar|}}
   foo {{bar}} 
{{/with}}

to render

foo false

or maybe

foo

The fact that it wasn't rendered at all was unexpected to me. I'm not sure if this is a bug or simply unclear in the docs.

@damncabbage
Copy link

damncabbage commented Jun 20, 2016

It's explicitly checking for empty arrays, null, undefined, false (but not 0), and rendering any provided {{else}} block instead.

From your example:

  {{#with asetting as |bar|}}
    foo {{bar}} 
  {{else}}
    quux
  {{/with}}

It will print quux instead of the blank line it currently prints.

Whether that's a good idea is up for grabs, but at the very least this appears to be working as intended.

@danielsharvey
Copy link

It does seem to be operating as coded, but this behaviour does not appear to be covered in the documentation, and seems unexpected to my read.

The documentation says:

You might find a helper like this useful if a section of your JSON object contains deeply nested properties, and you want to avoid repeating the parent name. The above template could be useful with a JSON like ...

That is, the use case is aliasing as a way to avoid repeating the parent name. My expectation was that the contents would be rendered in all cases.

From the code I can see the else case, but this seems unintuitive in the context of the aliasing use case and is not documented.

For my 2c, I suggest removing the else case and having the contents rendered in all cases.

@nknapp
Copy link
Collaborator

nknapp commented Sep 1, 2016

It has been introduced here. There was no discussion, no complaint.
I doubt this will be reverted now. You probably should write your own helper supporting your semantics.

@danielsharvey
Copy link

danielsharvey commented Sep 1, 2016

Thanks @nknapp for the link to the pull request, which does explain things. And yes, I have already written my own handler :)

My interest is confirming intended usage and documenting it - I'd not seen the pull request you reference, which makes sense, although the documentation does not reflect this usage pattern.

Perhaps the suggestion should be for a {{#define}} helper or similar. My use case is similar to the documentation for with, except that I have multiple levels of contexts and so tracking the ../../../this etc becomes painful. Use of the with helper enables aliasing that works without the need for lots of ../'s which continually need adjusting if another level is introduced.

For example, I use the following to alias parameters to an inline partial:

{#*inline "reportHeaderRowGroup"}}
{{#with src as |src|}}
{{#with ../rowSpanContainer as |rowSpanContainer|}}
{{#with ../../dataRow as |dataRow|}}
{{#with ../../../reportData as |reportData|}}
...

Thoughts/suggestions?

@nknapp
Copy link
Collaborator

nknapp commented Apr 5, 2020

Closing due to inactivity. This is also now covered by examples in the documentation.

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

4 participants