Started

Selectors

Utilities

Animation

AJAX

CSS

Event

Manipulation

Cookie

String

Attributes

Data

Storage

Miscellaneous

$template

Rendering HTML with data.
$template( template, data )
  1. template [string]
    The string of template.
  2. data (optional) [object]
    The data will be rendered into the template.

Notes

The high performance template rendering system supported simple Mustache syntax. Supported template caching.

The template syntax is similar as Mustache with {{ and }} blocking and supported {{#xxx}} {{/xxx}} for traversal which supported {{.}} or {{this}} to indicates and output the current iterating item itself.

Example

HTML code
<div id="container"></div>
<div id="container2"></div>
<button onclick="start_templating()">Start render template</button>
JavaScript code
function start_templating()
{
	var template = "<div><h1>{{header}}</h1><h2>{{header2}}</h2><h3>{{header3}}</h3><h4>{{header4}}</h4><h5>{{header5}}</h5><h6>{{header6}}</h6><ul>{{#list}}<li>{{this}}</li>{{/list}}</ul><ul>{{#people}}<li>{{name}} - {{city}}</li>{{/people}}</ul></div>";

	var data = {
		header: "Header",
		header2: "Header2",
		list: ["1", "2", "3"],
		people: [
			{"name": "Tom", "city": "California"},
			{"name": "Jack", "city": "Newton"},
			{"name": "Jone", "city": "Tokyo"}
		]
	};

	$append($("container"), $template(template, data));

	// Output (formatted)
	// &lt;div&gt;
	//	&lt;h1&gt;Header&lt;/h1&gt;
	//	&lt;h2&gt;Header2&lt;/h2&gt;
	//	&lt;ul&gt;
	//		&lt;li&gt;1&lt;/li&gt;
	//		&lt;li&gt;2&lt;/li&gt;
	//		&lt;li&gt;3&lt;/li&gt;
	//	&lt;/ul&gt;
	//	&lt;ul&gt;
	//		&lt;li&gt;Tom - California&lt;/li&gt;
	//		&lt;li&gt;Jack - Newton&lt;/li&gt;
	//		&lt;li&gt;Jone - Tokyo&lt;/li&gt;
	//	&lt;/ul&gt;
	// &lt;/div&gt;

	// The template is compiled and cached, so rendering
	// the template again is faster.
	$append($("container2"), $template(template, data));

	// Or pre-compiled and cached the template at first
	// var tmpl = $template(template);
	// And pass data to the template
	// tmpl(data);
}
Demonstration