Simple JS Template Function

1
2
function $tmpl( t, o ){
for( var i in o ) t = t.replace( new RegExp('{'+i+'}', 'g' ), o[ i ] );
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Simple JS Template function

$tmpl( 'Hello {name}! {say}', { name: 'JavaScript', say: 'Whatsuuuuup!' } );
=> "Hello JavaScript! Whatsuuuuup!"

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.