Reputation: 1337
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>
Upvotes: 0
Views: 1626
Reputation: 4497
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.
Upvotes: 2
Reputation: 480
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.
Upvotes: 0