Clear Up
SharpKit Reference

Template Class

Represents an HTML fragment template. Templates may be precompiled for greater performance.

An instance of this class may be created by passing to the constructor either a single argument, or multiple arguments:

Single argument: String/Array

The single argument may be either a String or an Array:

  • String:

          
    var t = new Ext.Template("<div>Hello {0}.</div>");
                t.append('some-element', ['foo']);
                
  • Array:

    An Array will be combined with join('').

          
    var t = new Ext.Template([
                '<div name="{id}">',
                '<span class="{cls}">{name:trim} {value:ellipsis(10)}</span>',
                '</div>',
                ]);
                t.compile();
                t.append('some-element', {id: 'myid', cls: 'myclass', name: 'foo', value: 'bar'});
                

Multiple arguments: String, Object, Array, ...

Multiple arguments will be combined with join('').

  
var t = new Ext.Template(
            '<div name="{id}">',
            '<span class="{cls}">{name} {value}</span>',
            '</div>',
            // a configuration object:
            {
            compiled: true,      // compile immediately
            }
            );
            

Notes

  • For a list of available format functions, see Ext.util.Format.
  • disableFormats reduces apply time when no formatting is required.

Namespace: Ext

Base Types

Derived Types

Constructors

Methods

Name Description
append(object, object, object) Applies the supplied values to the template and appends the new node(s) to the specified el. For example usage see Ext.Template class docs.
apply(object) Returns an HTML fragment of this template with the specified values applied.
applyOut(object, JsArray) Appends the result of this template to the provided output array.
applyTemplate(object) Alias for apply. Returns an HTML fragment of this template with the specified values applied.
compile() Compiles the template into an internal function, eliminating the RegEx overhead.
from(object, object) Creates a template from the passed element's value (display:none textarea, preferred) or innerHTML.
insertAfter(object, object, object) Applies the supplied values to the template and inserts the new node(s) after el.
insertBefore(object, object, object) Applies the supplied values to the template and inserts the new node(s) before el.
insertFirst(object, object, object) Applies the supplied values to the template and inserts the new node(s) as the first child of el.
overwrite(object, object, object) Applies the supplied values to the template and overwrites the content of el with the new node(s).
set(JsString, object) Sets the HTML used as the template and optionally compiles it.

Fields

Name Description
compiled True to immediately compile the template. Defaults to false.
disableFormats True to disable format functions in the template. If the template doesn't contain format functions, setting disableFormats to true will reduce apply time. Defaults to false. Defaults to: false

Properties

Name Description
isTemplate true in this class to identify an object as an instantiated Template, or subclass thereof. Defaults to: true
© Copyright 2005-2011 SharpKit. All rights reserved.