Multiple test conditions in jQuery template "if"

3.5k views Asked by At

How can I test multiple test conditions using jQuery template "if"? For example, in any language I would do something like:

if(str1=='abc' && str2=='def'){
    //do something
}

But how can it be done using jQuery template "if" clause? I tried following but it doesn't work.

{{if str1=='abc' && str2=='def'}}
    //do something
{{/if}}
2

There are 2 answers

0
Darko Pecevski On

You must create some helper function in order to check multiple "AND" conditions. On the other hand, || (OR) can be done this way: {{if x===1 y!==2}}

0
Abhishek On

You can do it like this.

AND statements

{{if $data.str1=='abc' && $data.str2=='def'}}
    //do something
{{/if}}

Similarly OR statements

{{if $data.str1=='abc' || $data.str2=='def'}}
    //do something
{{/if}}

Reference:https://github.com/BorisMoore/jquery-tmpl/issues/70