Created
November 30, 2011 14:15
-
-
Save garth/1409209 to your computer and use it in GitHub Desktop.
Use requirejs to dynamically load sproutcore20 handlebars templates
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
// dynamically load sproutcore20 handlebars templates | |
// add this file to the same dir as your data-main js to load a template as a dependency do | |
// | |
// define(['template!template'] function(){ | |
// //do some SproutCore[ing] | |
// }); | |
// | |
// templates should be located in templates folder and have a .handlebars extension | |
// removed partial support {{> partial}} which doesn't work in SC.Handlebars use | |
// {{template partial}} instead | |
define('template', ['jquery', 'sproutcore'], function ($) { | |
return { | |
version: '0.1.0', | |
load: function (name, req, onLoad, config) { | |
if (SC.TEMPLATES[name]) { | |
onLoad(SC.TEMPLATES[name]); | |
} | |
else { | |
var path = req.toUrl('template/' + name + '.handlebars'); | |
$.get(path, function(text) { | |
var template = SC.Handlebars.compile(text); | |
SC.TEMPLATES[name] = template; | |
onLoad(template); | |
}); | |
} | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment