Nested mustache templates

I am wondering if this is possible. In this example, the HTML file will look like this:

{{i18n.sample_message}}

in my render function i have this:

var json = {
 i18n:i18n,
 sampleDate:'10/10/10'
}
$('div').html(Mustache.to_html(template,json);

      

The file i18n

is an object and has a key:

sample_message: some long message
date is: {{json.sampleDate}}


right now i'm getting {{json.sampleDate}}

on screen. I tried to end the string with a semicolon and use + to concatenate the value, but that didn't work either.

Until I put {{json.sampleDate}}

in the map i18n

, I changed my html to

{{i18n.sample_message}}{{json.sampleDate}}

      

I actually have some long paragraphs in which I need to insert some dynamic values.

+3


source to share


1 answer


I was able to get this to work ugly. Please comment / edit if there is anything cleaner / better.

I had to call Mustache.to_html twice.



var html = Mustache.to_html(template,json);
return Mustache.to_html(html,json);

      

Calling to_html again, Usatii found {{json.sampleDate}} and replaced it with the value in my json.

+1


source







All Articles