I would like to update the answer a bit, as I was just trying to handle it; and I used this answer as a reference.
Here are my findings:
The answer here is a bit outdated with the current version of Mustache (which is understandable, since it is quite old)
- Mustache.to_html is now deprecated, but still exists as a simple wrapper around Mustache.render for backward compatibility. Check out this link .
Also, I found the Marionette.Renderer.render redefinition, as in the accepted answer above, completely bypasses the Marionette.TemplateCache layer, which may not be desirable.
Here is the source for the Marionette.Renderer.render method:
// Source: http://bit.ly/1f7CBRy render: function(template, data){ if (!template) { var error = new Error("Cannot render the template since it false, null or undefined."); error.name = "TemplateNotFoundError"; throw error; } var templateFunc; if (typeof template === "function"){ templateFunc = template; } else { templateFunc = Marionette.TemplateCache.get(template); } return templateFunc(data); }
As you can see, it accesses the Marionette.TemplateCache.get method, and the answer above does nothing to support this functionality.
Now, to get to my solution (note: this answer is not wrong, this is my approach to support Marionette.TemplateCache level):
As the comments above suggest , override compileTemplate :
Marionette.TemplateCache.prototype.compileTemplate = function(rawTemplate) {
This is where JSFiddle works as proof .
In the fiddle, I also redefined Marionette.TemplateCache.loadTemplate to demonstrate that it only calls once. The body of the function adds only debug output, and then re-implements most of the original functions (minus error handling).
Lubricus
source share