Skip to content

Instantly share code, notes, and snippets.

@allanesquina
Last active August 29, 2015 14:01
Show Gist options
  • Save allanesquina/509026963579b865b869 to your computer and use it in GitHub Desktop.
Save allanesquina/509026963579b865b869 to your computer and use it in GitHub Desktop.
Render function
function render( tplName, data ) {
try {
var tpl = $( '#' + tplName )[0].innerHTML || {},
k, rx = /{\|\|.*?\|\|}/g, tmp ;
for( k in data ) {
tmp = new RegExp( '{\\|\\|data\\.'+ k +'\\|\\|}', 'g' );
tpl = tpl.replace( tmp, data[ k ] );
}
//Limpa dados que não foram encontrados
while ( tpl.match( rx ) ) {
tpl = tpl.replace( rx , '');
}
return tpl;
} catch ( e ) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment