Skip to content

Instantly share code, notes, and snippets.

@sifu
Created April 9, 2010 12:13
Show Gist options
  • Save sifu/361095 to your computer and use it in GitHub Desktop.
Save sifu/361095 to your computer and use it in GitHub Desktop.
function template( targetNode, templateNode_ ) {
var self = {};
var templateNode = templateNode_ || targetNode;
var templateString = $( templateNode ).innerHTML.replace( /^\s*<!--/, '' ).replace( /-->\s*$/, '' );
targetNode.innerHTML = '';
self.render = function( data ) {
targetNode.innerHTML = Mustache.to_html( templateString, data );
return data;
};
return self;
}
/* sample: */
var t = template( dojo.byId( 'whatever' ) );
t.render( { to_be_replaced: 'muhkuh' } );
<div id="whatever">
<--
{{ to_be_replaced }}
-->
</div>
<-- the template code has to be a comment to prevent the browser from mangling with it -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment