HTML templating
by amindunited
HTML
<demo></demo>
JavaScript
const processHTML = (HTML, scope) => {
const out = HTML.replace(/\$\{(\w*)\}/g, (match, gr) => {
return scope[gr];
});
// console.log('my output = ', out);
return out;
}
// write the string to the DOM
document.querySelector('demo').innerHTML = processHTML('<h1>${cheese} ${sandwhich}</h1>', {'cheese': 'brie', 'sandwhich': 'NOtAHotdog'});