Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render "0" value using a mustache template

I have a model with a attribute with a value of "0" (zero). My template looks something like this:

    {{#count}}{{{count}}} items{{/count}}
    {{^count}}-{{/count}}

If myModel.count = 0, the rendered html is nothing. It's like the value "count" is null and not null at the same time.

Mustache documentation for this case: https://github.com/janl/mustache.js#inverted-sections

like image 462
JT703 Avatar asked Nov 04 '22 11:11

JT703


1 Answers

@bobthecow answered it in his comment:

It won't display a zero because zero is falsey. One option to get it to display is to set it to a non-falsey value (like the string '0')

like image 96
JT703 Avatar answered Nov 09 '22 16:11

JT703