using multiple clauses in if in jQuery template

I want to use a variable in the if clause which is in jQuery template. Console log says:

Uncaught Syntax Error: Unexpected token {

Here is my code:

 var isActive = true;
                    var isPasive = false;
                    var isGuest = false;
                      var tmp = '<script>' +

            '{{each hastalar}}' +
                '<a href="#" class="patientRow" data-name="${$value.M_AdiSoyadi}" data-tc="${$value.M_TcKimlikNo}" data-tahlilgunu="${$value.M_TahlilGunu}"> ${M_AdiSoyadi}' +
                '{{if $value.M_HastaBulunmaDurumu == "1" && ${isActive} }}' +
                    '<img id="imgMember_${$value.M_TcKimlikNo}" src="images/greenmember.png" title="Hasta klinik ve DYOB kayıtlarıyla örtüşüyor." style="width:15px;height:15px;"/>' +

                '{{else  $value.M_HastaBulunmaDurumu == "2" }}' +
                   '<img id="imgMember_${M_TcKimlikNo}" src="images/bluemember.png" title="Hasta kliniğinizde mevcut fakat DYOB sisteminde sizin kliniğinizde görünmüyor. Lütfen DYOB sistmine hasta kaydını yapınız." style="width:15px;height:15px;"/>' +
                '{{else $value.M_HastaBulunmaDurumu == "3"}}' +
                    '<img id="imgMember_${M_TcKimlikNo}" src="images/redmember.png" title="Hasta kliniğinizde mevcut değil fakat DYOB sisteminde sizin kliniğinizde görünüyor. Lütfen kan tahlili yapılan hastaların listesini kontrol ediniz." style="width:15px;height:15px;"/>' +
                '{{/if}}' +
                '<img id="imgResult_${$value.M_TcKimlikNo}"/>' +
                '<img id="imgInfo_${$value.M_TcKimlikNo}"/>' +

                '</a>' +
            '{{/each}}' +

I use jquery.tmpl.min.js. What should I do to use the variable in if clause?

1 thought on “using multiple clauses in if in jQuery template”

  1. For a generic approach of replacing your variables in JavaScript strings you could you the following snippet;

    var tmp = '<script>' +
              ... +
              .replace('${isActive}', isActive)
              .replace('${isPassive}', isPassive)
              .replace('${isGuest}', isGuest)

    For a more detailed solution on your problem, we need information about the framework and template engine which you are using.


    I noticed that the closing script tag causes an error. YOu might want to escape the closing script tag at the like so:


Leave a Comment