Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function render(tpl,data){
- var matches = tpl.match(/{[^\}]+}/g);
- for(var i in matches){
- var rep = eval("data."+matches[i].replace('{','').replace('}',''));
- tpl = tpl.replace(matches[i],rep);
- }
- return tpl;
- }
- alert(render("{a} is all that i've {b.a} {b.b} {b.c}", {a:"this", b:{a:"ever",b:"really",c:"needed"}}))
Advertisement
Add Comment
Please, Sign In to add comment