Outside steering patterns with puppet

In my application, I added the Marionette.sync plugin and overriding these methods:

Backbone.Marionette.TemplateCache.prototype.loadTemplate = function (templateId, callback) { var tmpId = templateId.replace("#", ""), url = "/app/templates/" + tmpId + ".html"; $.get(url, function (templateHtml) { compiledTemplate = Handlebars.compile($(templateHtml).html()) callback.call(this, compiledTemplate); }); }; Backbone.Marionette.Renderer.renderTemplate = function (template, data) { template(data); }; 

But that doesn't work, any ideas?

+4
source share
1 answer

I assume that you are using v0.9 from Marionette, since you mentioned the Marionette.Async plugin.

Changing the Renderer is not mentioned a bit in the method name, and nothing else calls your TemplateCache object.

If you intend to use the pre-compiled Handlebars functions, you only need to do this:

 Backbone.Marionette.Renderer.render = function(template, data){ return template(data); }; 

If you intend to download the template asynchronously and then compile using TemplateLoader, your code should look like this:

 Backbone.Marionette.TemplateCache.prototype.loadTemplate = function (templateId, callback) { var tmpId = templateId.replace("#", ""), url = "/app/templates/" + tmpId + ".html"; $.get(url, function (templateHtml) { compiledTemplate = Handlebars.compile($(templateHtml).html()) callback.call(this, compiledTemplate); }); }; Backbone.Marionette.Renderer.renderTemplate = function (templateId, data) { var renderer = $.Deferred(); Backbone.Marionette.TemplateCache.get(templateId, function(template){ var html = template(data); renderer.resolve(html); }); return renderer.promise(); }; 

Renderer is responsible for calling TemplateCache.


Side note: which wiki article / blog post / page / documentation did you use to get the code? I might have missed some pages that need to be updated.

+7
source

All Articles