jquery-tmpl

using "if"'s in jQuery tmpl

Is it possible to create if sentences inside a jQuery tmpl template? <script id="template" type="text/html"> <h1>${someVar}</h1> if (${intro}!="") <small>${intro}</small> endif <p>${restOfVariables}</p> </script> Now, this would only write out the if as text, so is there any way to do something like this? Or wo...

Append dynamic HTML elements through function call in jquery-tmpl

I am using the jquery-tmpl template library to build a dynamic <select> list. In my template I have a function call that returns all <option> elements from an existing <select> element on the page. In my template the function call executes successfully and returns the .html() from the existing <select> list but renders it as text in th...

Grails interferes with jquery-tmpl syntax

The jQuery templates plug-in uses ${foo} syntax (example in jquery.tmpl doc): $.tmpl( "<li>${Name}</li>", myData ) But Grails also uses it (example in Grails doc): <body> Hello ${params.name} </body> So when I include $.tmpl( "<li>${Name}</li>", myData ) in my .gsp, Grails renders it as $.tmpl( "<li></li>", myData );. Is there a...

Simplest way to get current item index within jQuery template

I am passing an array of objects to jQuery template (official jquery-tmpl plugin): $("#itemTmpl").tmpl(items).appendTo("body"); <script id="itemTmpl" type="text/x-jquery-tmpl"> <div class="item">Name: ${name}, Index: ${???}</div> </script> What is the easiest way to display item index in the template? Preferably without using sep...

how to tell if a property exists and is false

I am having a hard time determining if data passed into the jquery template exists and is false without getting errors. This is what I am using to test <html> <head> <title>jQuery Templates {{if}} logic</title> </head> <body> <p id="results"></p> <p>How do you test if the Value exists and is false?</p> <script id="testTemplate" type="...

Proper way to access a object property in a jquery-tmpl {{each}} statement

I'm using jquery-tmpl. My object model is simple -- SalesProspect, which contains a collection of SalesProspectAction objects. Both of those objects have a field named Status. How do I get the child's Status in the each loop? It always pulls the parent's. <script id="tmplActions" type="text/x-jquery-tmpl"> <p>${GuestName}</p> ...

How do I render a jQuery.tmpl Template to a String?

The documentation for jquery.tmpl uses .appendTo to insert the template into the DOM during the rendering process: $.tmpl( myTemplate, myData ).appendTo( "#target" ); I am attempting to convert an existing app from another templating engine, and my code needs to render a template into a string first before it is added to the DOM. Is t...

jquery-tmpl - template function not working

Hey! The following code: jQuery(document).ready(function($) { function getBooks() { var query = "ajax.php?do=allbooks"; $.ajax({ dataType: "jsonp", url: query, jsonp: "callback", success: showBooks }); } function showBooks(data)...

How do I cycle an odd/even class as it loops over the items?

Using the jquery-tmpl, I want to stripe presentation of the rows by adding a class to every second one, so from data ['Cat','Dog','Horse','Noddy'] it generates: <li>Cat</li> <li class="odd">Dog</li> <li>Horse</li> <li class="odd">Noddy</li> The solutions suggested here looked like the start of something that could be further refined f...

jquery template tags conflict with Django template!

Today I'm trying to play with jquery-tmpl {{if}} & {{else}} statements. <script id="mission-dialog" type="text/x-jquery-tmpl"> <h3>${name}</h3> <p>${description}</p> <ul> {{each(i,cond) conditions.data}} <li> <img src="${cond.image}"/> <h4>${cond.name}</h4> <p class="status...