Skip to content

Instantly share code, notes, and snippets.

@trey
Created May 18, 2012 03:08
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trey/2722910 to your computer and use it in GitHub Desktop.
Save trey/2722910 to your computer and use it in GitHub Desktop.
Using External Files as jQuery Templates

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:

$.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

@trey
Copy link
Author

trey commented Nov 6, 2013

@JoshMock Thanks for the info on text!. Some day I'm gonna pick your brain about how you use Require.js.

And, yes, I realize this entire example is way out of date and I wouldn't use $.tmpl anymore. Just remembered I had this Gist sitting around from a while back and thought it served the example well enough. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment