You create client-side jQuery templates by embedding content
within a <script type="text/html"> tag. For example, the
HTML below contains a <div> template container, as well as a client-side
jQuery “contactTemplate” template (within the <script
type="text/html"> element) that can be used to dynamically display
a list of contacts:
The {{= name }} and {{= phone }} expressions are used within
the contact template above to display the names and phone numbers of “contact”
objects passed to the template.
We can use the template to display either an array of
JavaScript objects or a single object. The JavaScript code below demonstrates
how you can render a JavaScript array of “contact” object using the above
template. The render() method renders the data into a string and appends the
string to the “contactContainer” DIV element:
When the page is loaded, the list of contacts is rendered by
the template. All of this template rendering is happening on the
client-side within the browser: