Very simple js template engine

(function() { UIUtility = { viewRegex: /\{\{([^\{\}]*)\}\}/g, // Simply replace {{key}} with its value in the template string and returns it populate: function(template, data) { template = template.replace(this.viewRegex, function (match, key) { //eval make it possible to reach nested objects return eval("data." + key) || ""; }); return template; } }; })();
Use `UIUtility.populate` to populate your string with data. That's it!

Happy coding!
Eeliya

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.