Skip to content

Instantly share code, notes, and snippets.

@ervinne13
Last active February 3, 2019 08:10
Show Gist options
  • Save ervinne13/a06dd89f323b40f60502138b1a9e6031 to your computer and use it in GitHub Desktop.
Save ervinne13/a06dd89f323b40f60502138b1a9e6031 to your computer and use it in GitHub Desktop.
Refactoring JavaScript: Separation of Concerns - Markup Code on JS Fix
<script src="js/tmpl.min.js"></script>
<script type="text/x-tmpl" id="tmpl-specific-widget-x">
<div id="specific-widget-x" class="specific-widget-x">
<h2>{%=o.title%}</h2>
<div class="specific-widget-x-body-classes">
{%=o.text%}
</div>
</div>
</script>
<script type="text/javascript">
let widgetData = {
title: "My Widget",
text: "JavaScript is Quirky",
};
document.getElementById("widget-container").innerHTML = tmpl("tmpl-specific-widget-x", widgetData);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment