JSFiddle - React, Tailwind, and code Playground

by _nderscore

JavaScript

var templates = function() {};

templates.prototype.compile = function(template, map) {    
    return (this[template] || '').replace(/\{\$(?:[^}]+)\}/g, function(x){
        return map[x.slice(2,-1)] || '';
    });
};

templates.prototype.myHTML =
'<div>\
    <h1>hello, {$name}.</h1>\
    <div>Welcome to {$place}!</div>\
</div>';

var t = new templates();

var html = t.compile('myHTML', {name:'bob', place:'the world'});

document.body.innerHTML = html;