Solutions Log

So I only have to figure things out once.

Using External Files as jQuery Templates

Previously…

If you want to keep your templates in external files, you can load the template in like so:

1
2
3
$.get('/js/templates/filename.html', function(template) {
  $.tmpl(template, data).appendTo('#whatever');
});

A couple of benefits of this method:

  • Organizing your templates into their own files is tidy.
  • Your syntax highlighter will be happier, since you’re not writing HTML between two <script> tags.

Source

Comments