News for hackers. Stuff that matters.
Re:Advanced JavaScript Techniques by Jasber on Friday October 09, 2009 @03:20PM (#872249)
One solution I've used for storing small templates in HTML: http://ejohn.org/blog/javascript-micro-templating/

  <script type="text/html" id="user_tmpl">
    <% for ( var i = 0; i < users.length; i++ ) { %>
      <li><a href="<%=users[i].url%>"><%=users[i].name%></a></li>
    <% } %>
  </script>
Quick tip: Embedding scripts in your page that have a unknown content-type (such is the case here - the browser doesn't know how to execute a text/html script) are simply ignored by the browser - and by search engines and screenreaders.

This is quick and dirty, but much more elegant than writing HTML in JS.

Re:Advanced JavaScript Techniques by warp on Saturday October 10, 2009 @10:49AM (#873354)
For anything slightly more involved I really like Pure as a javascript template engine, http://beebole.com/pure/.

Especially when working with something like json data generated elsewhere.