Easiest JQuery Template

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

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;

}

Previous
Copy MySQL from Old Server to New Server
Next
PHP Raw Curl

Keep Reading

Explore more articles and insights

Ork: SSH Server Automation in Go

Ork: SSH Server Automation in Go

Read Article
Deno Deploy Killed My Start Page

Deno Deploy Killed My Start Page

Read Article
Back to Golang: Why I Switched From Static to Dynamic Again

Back to Golang: Why I Switched From Static to Dynamic Again

Read Article
View All Blog Posts