Print Friendly

Class Ext.MasterTemplate

Package:Ext
Class:MasterTemplate
Extends:Template
Defined In:MasterTemplate.js
Provides a template that can have child templates. The syntax is:
var t = new Ext.MasterTemplate(
	'<select name="{name}">',
		'<tpl name="options"><option value="{value:trim}">{text:ellipsis(10)}</option></tpl>',
	'</select>'
);
t.add('options', {value: 'foo', text: 'bar'});
// or you can add multiple child elements in one shot
t.addAll('options', [
    {value: 'foo', text: 'bar'},
    {value: 'foo2', text: 'bar2'},
    {value: 'foo3', text: 'bar3'}
]);
// then append, applying the master template values
t.append('my-form', {name: 'my-select'});
A name attribute for the child template is not required if you have only one child template or you want to refer to them by index.

Properties   -  Methods   -  Events

Public Properties

Property Defined By
  disableFormats : Boolean Template
True to disable format functions (defaults to false)
  re : RegExp Template
The regular expression used to match template variables
  subTemplateRe : RegExp MasterTemplate
The regular expression used to match sub templates

Public Methods

Method Defined By
  MasterTemplate.fromString/HTMLElement el, Object config ) : void MasterTemplate
<static> Creates a template from the passed element's value (display:none textarea, preferred) or innerHTML. e....
  add[String/Number name], Array/Object values ) : MasterTemplate MasterTemplate
Applies the passed values to a child template.
  addAll() : void MasterTemplate
Alias for fill().
  appendString/HTMLElement/Ext.Element el, Object values, [Boolean returnElement] ) : HTMLElement/Ext.Element Template
Applies the supplied values to the template and appends the new node(s) to el.
  apply() : void Template
Alias for applyTemplate
  applyTemplateObject values ) : String Template
Returns an HTML fragment of this template with the specified values applied.
  compile() : Ext.Template Template
Compiles the template into an internal function, eliminating the RegEx overhead.
  fill[String/Number name], Array values, [Boolean reset] ) : MasterTemplate MasterTemplate
Applies all the passed values to a child template.
  insertAfterString/HTMLElement/Ext.Element el, Object values, [Boolean returnElement] ) : HTMLElement/Ext.Element Template
Applies the supplied values to the template and inserts the new node(s) after el.
  insertBeforeString/HTMLElement/Ext.Element el, Object values, [Boolean returnElement] ) : HTMLElement/Ext.Element Template
Applies the supplied values to the template and inserts the new node(s) before el.
  insertFirstString/HTMLElement/Ext.Element el, Object values, [Boolean returnElement] ) : HTMLElement/Ext.Element Template
Applies the supplied values to the template and inserts the new node(s) as the first child of el.
  overwriteString/HTMLElement/Ext.Element el, Object values, [Boolean returnElement] ) : HTMLElement/Ext.Element Template
Applies the supplied values to the template and overwrites the content of el with the new node(s).
  reset() : MasterTemplate MasterTemplate
Resets the template for reuse
  setString html, [Boolean compile] ) : Ext.Template Template
Sets the HTML used as the template and optionally compiles it.

Public Events

This class has no public events.

Property Details

disableFormats

public Boolean disableFormats
True to disable format functions (defaults to false)
This property is defined by Template.

re

public RegExp re
The regular expression used to match template variables
This property is defined by Template.

subTemplateRe

public RegExp subTemplateRe
The regular expression used to match sub templates
This property is defined by MasterTemplate.

Method Details

MasterTemplate.from

public function MasterTemplate.from( String/HTMLElement el, Object config )
<static> Creates a template from the passed element's value (display:none textarea, preferred) or innerHTML. e.g. var tpl = Ext.MasterTemplate.from('element-id');
Parameters:
  • el : String/HTMLElement
  • config : Object
Returns:
  • void
This method is defined by MasterTemplate.

add

public function add( [String/Number name], Array/Object values )
Applies the passed values to a child template.
Parameters:
  • name : String/Number
    (optional) The name or index of the child template
  • values : Array/Object
    The values to be applied to the template
Returns:
  • MasterTemplate
    this
This method is defined by MasterTemplate.

addAll

public function addAll()
Alias for fill().
Parameters:
  • None.
Returns:
  • void
This method is defined by MasterTemplate.

append

public function append( String/HTMLElement/Ext.Element el, Object values, [Boolean returnElement] )
Applies the supplied values to the template and appends the new node(s) to el.
Parameters:
  • el : String/HTMLElement/Ext.Element
    The context element
  • values : Object
    The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
  • returnElement : Boolean
    (optional) true to return a Ext.Element (defaults to undefined)
Returns:
  • HTMLElement/Ext.Element
    The new node or Element
This method is defined by Template.

apply

public function apply()
Alias for applyTemplate
Parameters:
  • None.
Returns:
  • void
This method is defined by Template.

applyTemplate

public function applyTemplate( Object values )
Returns an HTML fragment of this template with the specified values applied.
Parameters:
  • values : Object
    The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
Returns:
  • String
    The HTML fragment
This method is defined by Template.

compile

public function compile()
Compiles the template into an internal function, eliminating the RegEx overhead.
Parameters:
  • None.
Returns:
  • Ext.Template
    this
This method is defined by Template.

fill

public function fill( [String/Number name], Array values, [Boolean reset] )
Applies all the passed values to a child template.
Parameters:
  • name : String/Number
    (optional) The name or index of the child template
  • values : Array
    The values to be applied to the template, this should be an array of objects.
  • reset : Boolean
    (optional) True to reset the template first
Returns:
  • MasterTemplate
    this
This method is defined by MasterTemplate.

insertAfter

public function insertAfter( String/HTMLElement/Ext.Element el, Object values, [Boolean returnElement] )
Applies the supplied values to the template and inserts the new node(s) after el.
Parameters:
  • el : String/HTMLElement/Ext.Element
    The context element
  • values : Object
    The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
  • returnElement : Boolean
    (optional) true to return a Ext.Element (defaults to undefined)
Returns:
  • HTMLElement/Ext.Element
    The new node or Element
This method is defined by Template.

insertBefore

public function insertBefore( String/HTMLElement/Ext.Element el, Object values, [Boolean returnElement] )
Applies the supplied values to the template and inserts the new node(s) before el.
Parameters:
  • el : String/HTMLElement/Ext.Element
    The context element
  • values : Object
    The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
  • returnElement : Boolean
    (optional) true to return a Ext.Element (defaults to undefined)
Returns:
  • HTMLElement/Ext.Element
    The new node or Element
This method is defined by Template.

insertFirst

public function insertFirst( String/HTMLElement/Ext.Element el, Object values, [Boolean returnElement] )
Applies the supplied values to the template and inserts the new node(s) as the first child of el.
Parameters:
  • el : String/HTMLElement/Ext.Element
    The context element
  • values : Object
    The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
  • returnElement : Boolean
    (optional) true to return a Ext.Element (defaults to undefined)
Returns:
  • HTMLElement/Ext.Element
    The new node or Element
This method is defined by Template.

overwrite

public function overwrite( String/HTMLElement/Ext.Element el, Object values, [Boolean returnElement] )
Applies the supplied values to the template and overwrites the content of el with the new node(s).
Parameters:
  • el : String/HTMLElement/Ext.Element
    The context element
  • values : Object
    The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
  • returnElement : Boolean
    (optional) true to return a Ext.Element (defaults to undefined)
Returns:
  • HTMLElement/Ext.Element
    The new node or Element
This method is defined by Template.

reset

public function reset()
Resets the template for reuse
Parameters:
  • None.
Returns:
  • MasterTemplate
    this
This method is defined by MasterTemplate.

set

public function set( String html, [Boolean compile] )
Sets the HTML used as the template and optionally compiles it.
Parameters:
  • html : String
  • compile : Boolean
    (optional) True to compile the template (defaults to undefined)
Returns:
  • Ext.Template
    this
This method is defined by Template.

Ext - Copyright © 2006-2007 Ext JS, LLC
All rights reserved.