Shane
Shane

Reputation: 1216

Jquery templates, escape "${...}"

I have a piece of javascript code as follows:

var data = { ... };
var template = "<select>" +
                 "<option value='${0:###,###.##}'>Format as $</option>" + 
               "</select>";

$.tmpl(template, data).appendTo("#placeholder");

My problem is that I want to evaluate the "value='${0:###,###.##}'" as a string, but jQuery templates attempts to evaluate it as an object reference.

Is there a way to escape the ${} characters?

Cheers, Shane

Upvotes: 3

Views: 1385

Answers (1)

Sergey Ratnikov
Sergey Ratnikov

Reputation: 1296

Try to replace $ with its special HTML character &#36;

var data = { };
var template = "<select>" +
         "<option value='&#36;{0:###,###.##}'>Format as $</option>" + 
       "</select>";

$.tmpl( template, data).appendTo("#placeholder");

Upvotes: 5

Related Questions