Easiest JQuery Template

Here is the simplest JQuery template possible. It will get the template code from a div and replace the variables.


function template(templateId, data) {
        var data = typeof data === "undefined" ? {} : data;
        var tpl = $('#'+templateId).html();
        $.each(data, function (key, value) {
            tpl = tpl.split('$$' + key + '$$').join(value);
        tpl = tpl.replace(new RegExp("\\$\\$.*\\$\\$", "g"), "");
        return tpl;


Please Do Not Reprint This Article

This article is copyrighted. Please do not reproduce or distribute this article in whole or part, in any form. Links to this article are welcome

Other Related Articles