-
-
Save menacestudio/4515310 to your computer and use it in GitHub Desktop.
Handlebars: Loading external 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
/* | |
* Extends Handlebars with a basic get method for loading external | |
* Handlebars templates. Simply pass an options object which contains | |
* the following properties: | |
* - path (required) : Path to the external template file to be loaded | |
* - success (required) : Callback invoked with the compiled loaded template. | |
* - cache (optional) : true if the template is to be cached, otherwise false. | |
* | |
* In addition to the above arguments, any jQuery/Zepto.ajax options argument | |
* can be specified as well. | |
*/ | |
Handlebars.get = function( options ) { | |
var args = $.extend( {}, options, { | |
success : function( data ) { | |
options.success( Handlebars.compile( data ) ); | |
} | |
}); | |
$.ajax( args ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment