Created
May 26, 2020 20:02
-
-
Save danialkalbasi/8e57d23aec25222a453f26b5e11cf7f9 to your computer and use it in GitHub Desktop.
Render Variables in es5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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