Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Null should yield empty string when resolving variable #408

Merged

Conversation

lukaszb
Copy link
Contributor

@lukaszb lukaszb commented Jan 26, 2014

This is related to #236. Am upvoting for showing empty string when resolving null object.

This is more similar to engines that swig is based on (Jinja/Django both resolves None as empty strings) and most of the time is more desired (I guess) than opaque [Object object].

While writing tests was pretty straightforward, have to admit I am not sure about the implementation.

Let me know what you think.

@tweakmds
Copy link

I just switched from 0.14.0 to 1.3.2, and noticed that all my empty values are now rendered as "undefined".
This is also contrary to the documentation, which lists "If a variable is not defined, don't worry, your template won't explode. Instead, an empty-string will be output in its place"

@mannyvergel
Copy link

Please show empty string when value is null. Currently it shows [Object object]

@paularmstrong
Copy link
Owner

My only hesitations with this is that it suppresses some potential conditionals that one might do (see examples below)... however, they don't work as one might expect...

This doesn't work because null in the template is not actually null in javascript.

{% if foo === null %} ... {% endif %}

The JS equivalent would be:

if (ctx.foo === ctx.null) { ... }

The same can be said for undefined.

However, apparently I've never needed to do any comparisons on null or undefined and no one has complained thus far. I think this is one of those exceptions that's probably okay for Swig's way of doing things is okay to be different than JS.

paularmstrong added a commit that referenced this pull request Mar 6, 2014
Null must yield empty string when printing variables === `null`. Fixes gh-408, Fixes gh-236
@paularmstrong paularmstrong merged commit 4b61275 into paularmstrong:master Mar 6, 2014
@lukaszb
Copy link
Contributor Author

lukaszb commented Mar 6, 2014

Agree on JS vs Swig way. Thanks for the merge!

@fundon
Copy link

fundon commented Mar 27, 2014

@paularmstrong Please release a new version. Thanks!

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

Successfully merging this pull request may close these issues.

5 participants