Created
April 9, 2010 12:13
-
-
Save sifu/361095 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' } ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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