Skip to content

Instantly share code, notes, and snippets.

@efeminella
Created February 29, 2012 04:13
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save efeminella/1937609 to your computer and use it in GitHub Desktop.
Save efeminella/1937609 to your computer and use it in GitHub Desktop.
Loading external Handlebars Templates with jQuery or Zepto
/*
* 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 );
}
@emphaticsunshine
Copy link

You can attach get function to "Handlebars" prototype.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment