Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created March 28, 2014 16:49
Show Gist options
  • 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