Last active
December 15, 2015 07:39
-
-
Save chrishoage/5225216 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Backbone.Marionette.TemplateCache.prototype.loadTemplate = function(templateId){ | |
// load your template here, returning a the data needed for the compileTemplate | |
// function. For example, you have a function that creates templates based on the | |
// value of templateId | |
if (Handlebars.templates === undefined || Handlebars.templates[templateId] === undefined) { | |
var deffered = $.ajax({ | |
url : '/templates/' + templateId + '.handlebars', | |
dataType : 'text', | |
success : function(data) { | |
if (Handlebars.templates === undefined) { | |
Handlebars.templates = {}; | |
} | |
Handlebars.templates[templateId] = Handlebars.compile(data); | |
} | |
}); | |
} | |
// send the template back | |
return $.when(Handlebars.templates[templateId] || deffered); | |
} | |
Backbone.Marionette.TemplateCache.prototype.compileTemplate = function(rawTemplate) { | |
// use Handlebars.js to compile the template | |
return _.isFunction(rawTemplate) ? rawTemplate : Handlebars.compile(rawTemplate); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment