blueimp/JavaScript-Templates

JavaScript-Templates doesn't output 0 (zero)

Ranhiru opened this issue · 1 comments

I really don't know whether it's my fault, but I just can't make this library output a 0.

Here's the template

{% for (var i=0; i<o.numbers.length; i++) { %}
    <li>{%=o.numbers[i]%}</li>
{% } %}
</ul>

Here's the JavaScript object

{
    "numbers": [0, 1, 2, 3, 0, 1, 2, 3, 0]
}

All the other numbers are in the output except for number 0.

Tested in Chrome, Firefox and IE. Same issue was found.

The JavaScript Templates engine prints falsy values as empty strings.
That is, undefined, null, false, 0 and NaN will all be converted to ''.
To be able to print e.g. the number 0, convert it to a String before using it as an output variable:

<h3>{%=0+''%}</h3>

https://github.com/blueimp/JavaScript-Templates#templates-syntax