lightweight logicless templating with HTML escaping
-
Include jig.js
-
Put templates in
<script>elements<script data-template="comment" type="text/template"> <li><a href="/user/{{author.username}}">{{author.full_name}}</a>: {{{comment_html}}}</li> </script>
-
Render templates with
template.template_name(data)var html = template.comment({ author: { username: 'joey12', full_name: 'Joe Sparks' }, comment_html: 'Does <em>this</em> support <strong>markdown</strong>?' });
-
Append to DOM with
Element.insertAdjacentHTMLvar commentsEl = document.getElementById('comments'); commentsEl.insertAdjacentHTML('beforeend', html);