Skip to content

Instantly share code, notes, and snippets.

@garth
Created November 30, 2011 14:15
Show Gist options
  • Save garth/1409209 to your computer and use it in GitHub Desktop.
Save garth/1409209 to your computer and use it in GitHub Desktop.
Use requirejs to dynamically load sproutcore20 handlebars templates
// 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