Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
Jquery template - else if construct

I was trying to use an "else if" statement inside the jquery template block.I have seen in other samples that instead of writing if else, we can just put else.But this is not working for me, its throwing syntax error on the template.can any one help pls?

The acutual way it should work is like

if(Amount == "")
{
-
}
else if(balance == "")
{
*
}
else
{
Amount
}

I have mentioned below the jquery template syntax which i wrote to acheive this.

<script id="MyTemplate" type="text/x-jquery-tmpl">
    <tr style="background-color:#EFF3FB"><td onclick="test();">${CardNumber}</td><td>${PostDate}</td>
            <td>{{if (Amount == "")}}-
                {{else(balance == "")}}*                      
                {{else}}${Amount}
                {{/if}}
             </td>
             <td>${Description}</td></tr>
    </script>
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

The syntax is correct as per JQuery API. Maybe try removing the '(' parentheses?

{{if Amount == ""}}
   -
{{else balance == ""}}
   *                      
{{else}}
   ${Amount}
{{/if}}
over 4 years ago · Santiago Trujillo Report

0

I had a similar issue when performing an if statement inside a loop, when doing the if statement on an item of the loop.

Assuming you are having an issue for the same reason (I see that your question includes some td and tr so you're probably iterating through items and displaying the their content in a table. Then here is my answer:

<script type="text/x-jquery-tmpl" id="jqTemplate">
 <ul>
      {{each data.messagetext}}
         <li>
             Message # ${$index+1}: &quot;${$value}&quot; |
             Test result: {{if $value}}exists{{else}}does not exist{{/if}}
         </li> 
      {{/each}}
    </ul>
</script>

notice the dollar sign in {{if $value}}, this is the trick on the regular {{if value}}

if you want to check the field of an item you are iterating on you can do {{if $value.fieldname}}exists{{else}}does not exist{{/if}}

fiddle http://jsfiddle.net/x2Tac/

jquery-template doc http://www.jquerysdk.com/api/template-tag-if

over 4 years ago · Santiago Trujillo Report

0

The correct answer is:

{{else [Condition]}}

Make sure that you import the jquery template js.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!