The plugin allows to use the technique of the template, or to facilitate the creation of complex graphical structures, creating precisely the template "generic" which are then compiled from JavaScript objects or arrays and hung in the next page. The definition of a template is inside a tag <script> marked with the type -specific text/x-jquery?tmpl and is treated as a normal object jQuery. Here is a small example taken from the official documentation of the plugin:
Code:
<script id="cinemaTemplate" type="text/x-jquery-tmpl">
<li> <b> {$ Name} </ b> ($ {ReleaseYear}) </ li>
</ Script>
<script type="text/javascript">
var cinema = [
{Name: "Narnia", ReleaseYear: "2006"},
{Name: "Spiderman 3", ReleaseYear: "2007"},
{Name: "Resident Evil 4" ReleaseYear: "2010"}
];
/ / Render the template with the date and insert cinema
/ / The HTML rendered under the "cinemaList" element
$ ("# CinemaTemplate). Tmpl (cinema). AppendTo (" # cinemaList ");
</ Script>
<ul id="cinemaList"> </ ul>
This example creates a simple template (an element <li> with a particular label), which is then populated from an array and is hung in a <ul> already created page and retrieved via the id. One approach would not only facilitate the writing of the code (thus avoiding the creation of classical strings with concatenated values) but also the maintainability and elegance.
Bookmarks