Skip to content

Instantly share code, notes, and snippets.

@CColeson
Last active February 14, 2024 01:00
Show Gist options
  • Save CColeson/bcdb3fea343962aab21e8a92111b5d24 to your computer and use it in GitHub Desktop.
Save CColeson/bcdb3fea343962aab21e8a92111b5d24 to your computer and use it in GitHub Desktop.
Run ejs in the browser using fetch (web server required as fetching names.ejs would cause an error with CORS)
<div id="target"></div>
// keep in mind, you'll need to import ejs somehow
fetch("names.ejs").then(async res => {
const resText = await res.text();
document.getElementById("target").innerHTML = ejs.render(resText, {names: ["Corey", "Austin", "Sharon", "Justin"] });
})
<% for (let name of names) { %>
<div><%= name%></div>
<% } %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment