Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created March 28, 2014 16:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barneycarroll/9837437 to your computer and use it in GitHub Desktop.
Save barneycarroll/9837437 to your computer and use it in GitHub Desktop.
A recursive version of csi.js [https://github.com/LexmarkWeb/csi.js] using jQuery. Allows nested templates!
jQuery.csi = function csi( context ){
$( '[data-include]', context || document ).each( function fetchPartial(){
var $placeholder = $( this );
var location = $placeholder.attr( 'data-include' );
$.ajax( { url : location, async : false } ).done( function injectPartial( response ){
var $partial = $( response );
csi( $partial );
$placeholder.replaceWith( $partial );
} );
} );
};
$( jQuery.csi )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment