simple templating engine
1 2 function parseTemplate(content, data) { 3 content=String(content); 4 re = /\[\[(\w*)\]\]/gi; 5 6 return ( 7 content.replace( 8 re, 9 function ($1,$2,$3) { 10 return data[$2]; 11 } 12 ) 13 ); 14 }
DZone Snippets > evitiello > asp
12727 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Eric Vitiello http://www.leapfroginteractive.com
1 2 function parseTemplate(content, data) { 3 content=String(content); 4 re = /\[\[(\w*)\]\]/gi; 5 6 return ( 7 content.replace( 8 re, 9 function ($1,$2,$3) { 10 return data[$2]; 11 } 12 ) 13 ); 14 }