BorisMoore / jquery-tmpl

The original official jQuery Templates plugin. This project was maintained by the jQuery team as an official jQuery plugin. It is no longer in active development, and has been superseded by JsRender.
3.23k stars 1.01k forks source link

Error while using and in {{if}} #101

Closed dtarasiuk closed 13 years ago

dtarasiuk commented 13 years ago

{{if foo}} ok {{if foo && 1}} foo is not defined

same with {{if (foo) && (1==1)}}, {{if ((foo) && (1==1))}} etc variants

BorisMoore commented 13 years ago

Probably a dup of https://github.com/jquery/jquery-tmpl/issues/70.

Try using {{if $data.foo && 1}}.

BorisMoore commented 13 years ago

Closing, per comment above. If foo is false {{if foo &&1}} works but if foo may be undefined you need to put {{$data.foo && 1}} (assuming foo is a field you are testing for on your data).