Closed mic0331 closed 12 years ago
@mic0331 please read this section https://github.com/linkedin/dustjs/wiki/Dust-Tutorial#wiki-Logic_in_Templates
boolean false is falsy.
and any non empty string is truthy
So if current = false, dust will not even enter the {#current} block
If curious, see the dust.isEmpty method is the dust-core.js on how false/truth values are evaluated
BTW, the above template can be just simplified to
{?current} bbbbb {/eq} {:else} aaaaa {/current}
Any reason we need all these helpers?
Yes you are right this template is much simple to read and the helper is probably useless for what i m trying to do... but what I still have some issue to understand how I can evaluate a true/false value?
E.g.
If I use the model:
{
"Current":false
}
Or
{
"Current":true
}
The value is a Boolean not a string. The output will be always aaaaa
{?current}
bbbbb
{:else}
aaaaa
{/current}
Thanks for your help and sorry if my question is a dumb question...
No problem, it took me a while to understand all the truthy and falsy.
We have unit tests here to play around with : http://linkedin.github.com/dustjs/test/test.html
Have you tried it?
Current is upper case C, so in this case since it does not find the element in the JSON, it will always evaluate to false ( hence the else case )
Oh sorry I didn't notice upper case C ... Sorry for the waste of time it is now working for me. I will definitively spend more time in the documentation..
I actually played with the tester page but did not see the error...
Have a great day.
hello,
I have this model :
when i try to apply this dust template the output is empty :
If i simply add quotes to /false/ it works...
and the template :
output --> bbbbb
Is there something wrong with my code ? Does "select" support "pure" boolean types (boolean recorded with no quotes) ?
thanks for your input