Last active
December 19, 2015 05:49
-
-
Save aldwyish/5906937 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| Usage: Just include this script after Marionette and Handlebars loading | |
| IF you use require.js add script to shim and describe it in the requirements | |
| */ | |
| (function(Handlebars, Marionette) { | |
| Marionette.Handlebars = { | |
| path: 'templates/', | |
| extension: '.handlebars' | |
| }; | |
| Marionette.TemplateCache.prototype.loadTemplate = function(templateId) { | |
| var template, templateUrl; | |
| if (Handlebars.templates && Handlebars.templates[templateId]) { | |
| return Handlebars.templates[templateId]; | |
| } | |
| try{ | |
| template = Marionette.$(templateId).html(); | |
| } catch(e) {} | |
| if (!template || template.length === 0) { | |
| templateUrl = Marionette.Handlebars.path + templateId + Marionette.Handlebars.extension; | |
| Marionette.$.ajax({ | |
| url: templateUrl, | |
| success: function(data) { | |
| template = data; | |
| }, | |
| async: false | |
| }); | |
| if (!template || template.length === 0){ | |
| throw "NoTemplateError - Could not find template: '" + templateUrl + "'"; | |
| } | |
| } | |
| return template; | |
| }; | |
| Marionette.TemplateCache.prototype.compileTemplate = function(rawTemplate) { | |
| if (typeof rawTemplate === "function"){ | |
| return rawTemplate; | |
| } | |
| else { | |
| return Handlebars.compile(rawTemplate); | |
| } | |
| }; | |
| }(Handlebars, Marionette)); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jblanche check this one: https://gist.github.com/funkjedi/5732611