I found a few topics on it, but they all had different solutions, and most were from a while ago. I’m hoping someone can give me an easy way to do this.
I need to have the following on a page.
<div id="gleam_competition"></div>
<script>
function embedCompetition(el, html) {
el.innerHTML = html;
Array.from(el.querySelectorAll("script")).forEach(oldScript => {
const newScript = document.createElement("script");
Array.from(oldScript.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value));
newScript.appendChild(document.createTextNode(oldScript.innerHTML));
oldScript.parentNode.replaceChild(newScript, oldScript);
});
}
/* Replace with your embed code */
const embedCode = '<a class="e-widget generic-loader" href="MyURL" rel="nofollow">MyTEXT</a><script type="text/javascript" src="https://widget.gleamjs.io/e.js" async="true"><\/script>';
embedCompetition(document.querySelector('#gleam_competition'), embedCode);
</script>
And MyURL and MyTEXT would come from a database query.
I saw some things about using dmx-parse or running javascript in a page flow. Most recent solution I could find is
but I don’t really understand how to “use EJS templating to SSR the script src attribute”
I appreciate it if anyone can help me out on this.