Skip to content

Instantly share code, notes, and snippets.

@danialkalbasi
Created May 26, 2020 20:02
Show Gist options
  • Save danialkalbasi/8e57d23aec25222a453f26b5e11cf7f9 to your computer and use it in GitHub Desktop.
Save danialkalbasi/8e57d23aec25222a453f26b5e11cf7f9 to your computer and use it in GitHub Desktop.
Render Variables in es5
function render(html, variables) {
let htmlData = html;
Object.getOwnPropertyNames(variables).forEach((prop) => {
htmlData = htmlData.replace("$" + prop, variables[prop]);
});
return htmlData;
}
var variables = {
title: "The Last Dance",
price: "45$"
};
var pieceOfDom = "<div>The movie title is: $title and the price is: $price</div>";
console.log(render(pieceOfDom, variables));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment