I'm using mustache to render json data received through Ajax.
I want to render this number in currency format:
{{price}}
e.g.: 12300
How can I render it as:
"12,300"
using mustache templating engine ?
Mustache is very minimalistic and doesn't provide any support for this.
You either have to supply the formatted data or a function returning the formatted data
{ priceDecimal: function () { return formatDecimal(this.price); } }
Another alternative is to use handlebars.js which supports helper functions
Handlebars.registerHelper('decimal', function(number) {
return formatDecimal(number);
});
and use it like this
{{decimal price}}