Is it possible to handle null and false differently in mustache (or hogan)?

1.7k Views Asked by At

I have some data which (quite reasonably) uses null and false for different meanings.

Eg, a test which has failed is false, whereas one which has not completed is null.

I understand mustache sections treat null/false the same in most cases. Is there any way I can make mustache (or hogan, more specifically, which is the implementation I'm using) treat null and false differently?

Or should I hack in some additional boolean for 'tests in progress' or somesuch?

1

There are 1 best solutions below

0
On BEST ANSWER

all falsey values are interpreted as false in the Mustache spec [1], with the exception of the empty string which most javascript implementations interpret as falsey but Hogan gets it as truthy [2] (because the canon Ruby implementation does it like that, and the spec omits the empty string so implementors are free to interpret at will).

So in short, null and false are the same in Mustache and Hogan, you will need another property to convey this differentiation.