2

I want to perform an if check with in jquery template:

jquery template

<script id="CardWallItem" type="text/x-jquery-tmpl">
    <div id="lc${ProductId}" class="card">
        <input class="ItemId" type="hidden" value="${CardId}"/>
        <a href="" class="oCloseButton" onclick="return $$.laneItems.deleteLane(this);">x</a>
        if($.parent().find('.ItemId').val() == ${EntityId}){
        <p class="text" onclick="return $$.laneItems.editCard(this);">${Desc}</p> 
        <div class="edit bg" style="display:none;">
            <input class="editval" type="text" maxlength="20" />
            <a class="button" href="" onclick="return $$.laneItems.saveTitle(this);">Save</a> 
        </div>
        }
    </div>
    <br /><br />
</script>

and as you can see the if check in between, this one:

if($.parent().find('.ItemId').val() == ${EntityId}){
            <p class="text" onclick="return $$.laneItems.editCard(this);">${Desc}</p> 
            <div class="edit bg" style="display:none;">
                <input class="editval" type="text" maxlength="20" />
                <a class="button" href="" onclick="return $$.laneItems.saveTitle(this);">Save</a> 
            </div>
            }

as the output of this is that it is printing whole if statement on page. So can anyone please tell me what I should do?

2 Answers 2

2

The syntax of conditionals in jquery templates is different:

{{if CONDITION}}

{{else}}

{{/if}}

See the documentation of the if template tag.

Sign up to request clarification or add additional context in comments.

2 Comments

{{ if($.parent().find('.ItemId').val() == ${EntityId}) }} some code {{/if}}, is this correct?
I'm not sure that you can access the dom there. Give it a try.
2

JQuery template itself is any HTML markup, along with any of a set of template tags which enable some very rich scenarios for creating data-driven UI. The current set of tags that are supported in jQuery templates are:

- ${...}: Evaluate fields or expression
- {{each ...}}...{{/each}}: Iterate without creating template items
- {{if ...}}...{{else ...}}...{{/if}}: Conditional sections
- {{html ...}}: Insert markup from data
- {{tmpl ...}}: Composition, as template items
- {{wrap ...}}...{{/wrap}}: Composition, plus incorporation of wrapped HTML

And for more details and example please visit here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.