0

Is it possible to perform javscript operations within the jQuery template markup?

I have a collection of objects for which I only want to show certain information on the first iteration through the template.

<script type="text/javascript">
    var x = 0; // Counter
</script>

<script id="QuoteTemplate" type="text/x-jQuery-tmpl">

     {{if x = 0 }}
        // Show Stuff
     {{ x++ }}

</script>

2 Answers 2

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.

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

Comments

0

I don't think it a bad question. The doc is clear but you have to find it on the ${} syntax.

${fieldNameOrExpression} The name of a field on the current data item, or a JavaScript function or expression to be evaluated.

Try $.tmpl('<p>${a + 1}</p>', {a: 1}) in a console.

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.