Chapter 11

jQuery Templates

WHAT’S IN THIS CHAPTER?

  • Why Use Templates?
  • The Past, Present, and Future of jQuery Templates
  • Creating and Using Templates

In this chapter, you learn about the jQuery Template plugin. jQuery Templates are a standard way of marrying data and markup snippets. If you’re familiar with template engines like Freemarker or Mustache, you’ll recognize a lot of what jQuery Templates try to accomplish. If you’ve done any Ajax-based development, you’ve had to build blocks of HTML for insertion into the document based on the result of an Ajax request or other user interaction. Typically, this has meant concatenating strings or building elements using native DOM methods and then inserting them into the DOMr. jQuery Templates simplify and standardize this common task.

In this chapter, you learn about the two ways to create templates: using specially crafted script tags to define them and using pure JavaScript to define them using JavaScript strings. You’ll also explore the template tags available for greater control over content and you learn strategies for implementing templates in the most efficient way possible. You also get a look at the planned roadmap for the new version of the Template plugin.

TAMING A TANGLE OF STRINGS

If you’ve done JavaScript development for any length of time, you’ve run into code similar to the following sample. In it, a collection of data about a comic book series is looped through to build out new content to be appended to the document. ...

Get Professional jQuery now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.