Created
April 24, 2022 02:31
-
-
Save CColeson/342769d3aa2c55ca3b18774aa12dbf39 to your computer and use it in GitHub Desktop.
Render ejs using a template's innerHTML
This file contains hidden or 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
<template id="names"> | |
<% for (let name of names) { %> | |
<div><%= name%></div> | |
<% } %> | |
</template> | |
<div id="target"></div> |
This file contains hidden or 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
const templateHTML = document.getElementById("names") | |
.innerHTML | |
.replace(/\</g, "<") | |
.replace(/\>/g, ">"); | |
document.getElementById("target").innerHTML = ejs.render(templateHTML, {names: ["corey", "noah", "alex", "dan"]}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment