Skip to content

Instantly share code, notes, and snippets.

@CColeson
Created April 24, 2022 02:31
Show Gist options
  • Save CColeson/342769d3aa2c55ca3b18774aa12dbf39 to your computer and use it in GitHub Desktop.
Save CColeson/342769d3aa2c55ca3b18774aa12dbf39 to your computer and use it in GitHub Desktop.
Render ejs using a template's innerHTML
<template id="names">
<% for (let name of names) { %>
<div><%= name%></div>
<% } %>
</template>
<div id="target"></div>
const templateHTML = document.getElementById("names")
.innerHTML
.replace(/\&lt;/g, "<")
.replace(/\&gt;/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