Last active
February 14, 2024 01:00
-
-
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)
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
<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
// 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"] }); | |
}) |
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
<% 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