Mustache nested templates

Go To StackoverFlow.com

3

I am wondering if this is possible. In this example the HTML file would be:

{{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 i18n file is an object and would have a key:

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

right now I get {{json.sampleDate}} on the screen. I have tried ending the string at the semicolon and using + to concatenate the value but that did not work either.

For the time being I am not putting {{json.sampleDate}} in the i18n map I changed my html to

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

In reality I have some long paragraphs that I need to inject some dynamic values into.

2012-04-04 17:55
by Barry


1

I was able to get this working in an ugly way. Please comment/edit if there is something cleaner/better.

I had to call Mustache.to_html twice.

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

By calling to_html again, Mustache found {{json.sampleDate}} and replaced it with the value in my json.

2012-04-05 16:11
by Barry
After some thought I moved away from the i18n having handlebars in it and arranged my HTML differently. Stylistically I think it is cleaner - Barry 2012-04-05 16:35
Ads