.ht()
Replaces the content of the list elements with the HTML generated using the given template.
Complete distribution only, not available in stand-alone modules.
Syntax Variants
list.ht(templateString, object...)
list.ht(templateFunction, object...)
list.ht(idSelector, object...)
Parameters
- templateString
- the template using
template()syntax. Please note, because this is a template, you should avoid creating the template itself dynamically, as compiling templates is expensive and Minified will cache only a limited number of templates. Exception: If the template string does not use any template functionality (no {{}}), it does not need to be compiled and won't be cached.
The template will useescapeHtml()as escape function, so all template substitutions will be HTML-escaped, unless you use triple curly-braces. - templateFunction
- instead of a HTML template, ht() can also use a template function, e.g. one
created by
template(). It will be invoked with the object as only argument. - idSelector
- if you pass an ID CSS selector in the form "#myScript", Minified will recognize this and use the content of the specified <script> element as template. This allows you to put your template into a <script> tag with a non-JavaScript type (see example). Any string that starts with '#' and does not contain any spaces is used as selector.
- object (optional)
- one or more objects to pass to the template. If object is not set, the template is called with undefined as object. If exactly one object is given, it is passed directly to the template. If you specify more than one object, they are merged.
- (return value)
- the current list
Description
Replaces the content of the list elements with the HTML generated using the given template. The template uses
template() syntax and HTML-escaped its output using escapeHtml().
Example
When you have a HTML snippet like this:
<div id="price"></div>Then you can format the price value like this:
var price = 14.9;
$('#price').ht('<b>${{::0.00}}</b>', price);
Results in:
<div id="price"><b>$14.90</b></div>
Example
Render a list of names:
var names = [ {first: 'James', last: 'Sullivan'},
{first: 'Michael', last: 'Wazowski'} ];
$('#list').ht('<h2>{{listName}}</h2>'+
'<ul>{{each n: names}}<li>{{n.first}} {{n.last}}</li>{{/each}}</ul>',
{listName: 'Guys', names: names});
The code creates this:
<h2>Guys</h2> <ul><li>James Sullivan<li><li>Michael Wazowski</li></ul>
Example
You can store templates in <script> tags. First you need to create a <script> tag with a type not supported by the browser and put your template in there, like this:
<script id="myTimeTpl" type="minified-template">The time is {{HH:mm:ss}}.</script>
Then you can specify the tag's id directly to access it:
$('#timeDisplay').ht('#myTimeTpl', new Date());
See also..
HTML()creates only the nodes and can be used withadd()and other methods to add the nodes to the DOM, giving you more flexibility than ht().
Comments
comments powered by DisqusFunctions
- $() Web
- list.length Web, Util
- $$() Web
- $.getCookie()
- $.loop() Web
- $.off() Web
- $.parseJSON() Web
- $.ready() Web
- $.request() Web
- $.setCookie()
- $.toJSON() Web
- $.wait()
- .add() Web
- .addAfter() Web
- .addBefore() Web
- .addFront() Web
- .animate() Web
- .array() Util
- .call() Util
- .clone() Web
- .collect() Web, Util
- .contains() Util
- .dial() Web
- .each() Web, Util
- .endsWith() Util
- .equals() Util
- .fill() Web
- .filter() Web, Util
- .find() Web, Util
- .findLast() Web, Util
- .get() Web
- .hide() Web
- .ht()
- .intersection() Util
- .is() Web
- .join() Util
- .map() Util
- .merge() Util
- .next() Web
- .not() Web
- .offset()
- .on() Web
- .onChange() Web
- .onClick() Web
- .onFocus() Web
- .onOver() Web
- .only()
- .per() Util
- .reduce() Util
- .remove() Web
- .replace() Web
- .reverse() Util
- .select() Web
- .set() Web
- .show() Web
- .sort() Util
- .startsWith() Util
- .sub() Web, Util
- .text() Web
- .toObject() Util
- .toggle() Web
- .trav() Web
- .trigger() Web
- .uniq() Util
- .unite() Util
- .up() Web
- .values() Web
- EE() Web
- HTML() Web
- M Web, Util
- MINI.getter Web
- MINI.setter Web
- Minified Lists Web, Util
- Promise Web, Util
- _() Util
- _.bind() Util
- _.copyObj() Util
- _.dateAdd() Util
- _.dateClone() Util
- _.dateDiff() Util
- _.dateMidnight() Util
- _.eachObj() Util
- _.escapeHtml() Util
- _.escapeRegExp() Util
- _.extend() Util
- _.filterObj() Util
- _.format() Util
- _.formatHtml() Util
- _.formatValue() Util
- _.isBool() Util
- _.isDate() Util
- _.isEmpty() Util
- _.isFunction() Util
- _.isList() Util
- _.isNumber() Util
- _.isObject() Util
- _.isString() Util
- _.isValue() Util
- _.keys() Util
- _.mapObj() Util
- _.pad() Util
- _.parseDate() Util
- _.parseNumber() Util
- _.partial() Util
- _.promise()
- _.range()
- _.template() Util
- _.toString() Util
- _.trim() Util
- _.values() Util
- define() Web, Util
- promise.always()
- promise.error() Web, Util
- promise.fire()
- promise.stop()
- promise.then() Web
- require() Web, Util
- How to...