Never been to DZone Snippets before?

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

simple templating engine (See related posts)

this will replace variables within a string that are denoted as [[variable]] and will replace it with the value of data[variable]


function parseTemplate(content, data) {
	content=String(content);
	re = /\[\[(\w*)\]\]/gi;

	return (
		content.replace(
			re, 
			function ($1,$2,$3) {
				return data[$2];
			}
		)
	);
}

You need to create an account or log in to post comments to this site.


Click here to browse all 5137 code snippets

Related Posts