Created
November 4, 2022 15:39
-
-
Save frostzzone/e6854f302c1ff1968970633c4ba82c78 to your computer and use it in GitHub Desktop.
Using ejs browser client
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
<!-- File 1/1 --> | |
<body> | |
<template id="names"> | |
<% for (let name of names) { %> | |
<div><%= name%></div> | |
<% } %> | |
</template> | |
<!-- Import ejs --> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/ejs.min.js"></script> | |
<div id="target"></div> | |
<script> | |
const templateHTML = document.getElementById("names") | |
.innerHTML | |
.replace(/\</g, "<") | |
.replace(/\>/g, ">"); | |
document.getElementById("target").innerHTML = ejs.render(templateHTML, {names: ["corey", "noah", "alex", "dan"]}); | |
</script> | |
</body> |
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
<!-- File 1/2 --> | |
<body> | |
<main id="target"></main> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/ejs.min.js"></script> | |
<script> | |
fetch("names.ejs").then(async res => { | |
const resText = await res.text(); | |
document.getElementById("target").innerHTML = ejs.render(resText, {names: ["corey", "noah", "alex", "dan"]}); | |
}) | |
</script> | |
</body> |
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
<!-- File 2/2 --> | |
<% 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