Skip to content

Instantly share code, notes, and snippets.

@bicherele
Forked from efeminella/gist:1937609
Created July 12, 2012 11:38
Show Gist options
  • Save bicherele/3097633 to your computer and use it in GitHub Desktop.
Save bicherele/3097633 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 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment