Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / docs / source / XTemplate.html
index 41d600a..883120f 100644 (file)
-<html>
-<head>
-  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
-  <title>The source code</title>
-    <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
-    <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
-</head>
-<body  onload="prettyPrint();">
-    <pre class="prettyprint lang-js">/*!
- * Ext JS Library 3.3.1
- * Copyright(c) 2006-2010 Sencha Inc.
- * licensing@sencha.com
- * http://www.sencha.com/license
- */
-<div id="cls-Ext.XTemplate"></div>/**
- * @class Ext.XTemplate
+<!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-XTemplate'>/**
+</span> * @class Ext.XTemplate
  * @extends Ext.Template
- * <p>A template class that supports advanced functionality like:<div class="mdetail-params"><ul>
- * <li>Autofilling arrays using templates and sub-templates</li>
- * <li>Conditional processing with basic comparison operators</li>
- * <li>Basic math function support</li>
- * <li>Execute arbitrary inline code with special built-in template variables</li>
- * <li>Custom member functions</li>
- * <li>Many special tags and built-in operators that aren't defined as part of
- * the API, but are supported in the templates that can be created</li>
- * </ul></div></p>
- * <p>XTemplate provides the templating mechanism built into:<div class="mdetail-params"><ul>
- * <li>{@link Ext.DataView}</li>
- * <li>{@link Ext.ListView}</li>
- * <li>{@link Ext.form.ComboBox}</li>
- * <li>{@link Ext.grid.TemplateColumn}</li>
- * <li>{@link Ext.grid.GroupingView}</li>
- * <li>{@link Ext.menu.Item}</li>
- * <li>{@link Ext.layout.MenuLayout}</li>
- * <li>{@link Ext.ColorPalette}</li>
- * </ul></div></p>
- *
- * <p>For example usage {@link #XTemplate see the constructor}.</p>
+ * &lt;p&gt;A template class that supports advanced functionality like:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
+ * &lt;li&gt;Autofilling arrays using templates and sub-templates&lt;/li&gt;
+ * &lt;li&gt;Conditional processing with basic comparison operators&lt;/li&gt;
+ * &lt;li&gt;Basic math function support&lt;/li&gt;
+ * &lt;li&gt;Execute arbitrary inline code with special built-in template variables&lt;/li&gt;
+ * &lt;li&gt;Custom member functions&lt;/li&gt;
+ * &lt;li&gt;Many special tags and built-in operators that aren't defined as part of
+ * the API, but are supported in the templates that can be created&lt;/li&gt;
+ * &lt;/ul&gt;&lt;/div&gt;&lt;/p&gt;
+ * &lt;p&gt;XTemplate provides the templating mechanism built into:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
+ * &lt;li&gt;{@link Ext.view.View}&lt;/li&gt;
+ * &lt;/ul&gt;&lt;/div&gt;&lt;/p&gt;
  *
- * @constructor
- * The {@link Ext.Template#Template Ext.Template constructor} describes
+ * The {@link Ext.Template} describes
  * the acceptable parameters to pass to the constructor. The following
- * examples demonstrate all of the supported features.</p>
+ * examples demonstrate all of the supported features.&lt;/p&gt;
  *
- * <div class="mdetail-params"><ul>
+ * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  *
- * <li><b><u>Sample Data</u></b>
- * <div class="sub-desc">
- * <p>This is the data object used for reference in each code example:</p>
- * <pre><code>
+ * &lt;li&gt;&lt;b&gt;&lt;u&gt;Sample Data&lt;/u&gt;&lt;/b&gt;
+ * &lt;div class=&quot;sub-desc&quot;&gt;
+ * &lt;p&gt;This is the data object used for reference in each code example:&lt;/p&gt;
+ * &lt;pre&gt;&lt;code&gt;
 var data = {
-    name: 'Jack Slocum',
-    title: 'Lead Developer',
-    company: 'Ext JS, LLC',
-    email: 'jack@extjs.com',
-    address: '4 Red Bulls Drive',
-    city: 'Cleveland',
-    state: 'Ohio',
-    zip: '44102',
-    drinks: ['Red Bull', 'Coffee', 'Water'],
-    kids: [{
-        name: 'Sara Grace',
+name: 'Tommy Maintz',
+title: 'Lead Developer',
+company: 'Sencha Inc.',
+email: 'tommy@sencha.com',
+address: '5 Cups Drive',
+city: 'Palo Alto',
+state: 'CA',
+zip: '44102',
+drinks: ['Coffee', 'Soda', 'Water'],
+kids: [{
+        name: 'Joshua',
         age:3
     },{
-        name: 'Zachary',
+        name: 'Matthew',
         age:2
     },{
-        name: 'John James',
+        name: 'Solomon',
         age:0
-    }]
+}]
 };
- * </code></pre>
- * </div>
- * </li>
+ &lt;/code&gt;&lt;/pre&gt;
+ * &lt;/div&gt;
+ * &lt;/li&gt;
  *
  *
- * <li><b><u>Auto filling of arrays</u></b>
- * <div class="sub-desc">
- * <p>The <b><tt>tpl</tt></b> tag and the <b><tt>for</tt></b> operator are used
+ * &lt;li&gt;&lt;b&gt;&lt;u&gt;Auto filling of arrays&lt;/u&gt;&lt;/b&gt;
+ * &lt;div class=&quot;sub-desc&quot;&gt;
+ * &lt;p&gt;The &lt;b&gt;&lt;tt&gt;tpl&lt;/tt&gt;&lt;/b&gt; tag and the &lt;b&gt;&lt;tt&gt;for&lt;/tt&gt;&lt;/b&gt; operator are used
  * to process the provided data object:
- * <ul>
- * <li>If the value specified in <tt>for</tt> is an array, it will auto-fill,
- * repeating the template block inside the <tt>tpl</tt> tag for each item in the
- * array.</li>
- * <li>If <tt>for="."</tt> is specified, the data object provided is examined.</li>
- * <li>While processing an array, the special variable <tt>{#}</tt>
- * will provide the current array index + 1 (starts at 1, not 0).</li>
- * </ul>
- * </p>
- * <pre><code>
-&lt;tpl <b>for</b>=".">...&lt;/tpl>       // loop through array at root node
-&lt;tpl <b>for</b>="foo">...&lt;/tpl>     // loop through array at foo node
-&lt;tpl <b>for</b>="foo.bar">...&lt;/tpl> // loop through array at foo.bar node
- * </code></pre>
+ * &lt;ul&gt;
+ * &lt;li&gt;If the value specified in &lt;tt&gt;for&lt;/tt&gt; is an array, it will auto-fill,
+ * repeating the template block inside the &lt;tt&gt;tpl&lt;/tt&gt; tag for each item in the
+ * array.&lt;/li&gt;
+ * &lt;li&gt;If &lt;tt&gt;for=&quot;.&quot;&lt;/tt&gt; is specified, the data object provided is examined.&lt;/li&gt;
+ * &lt;li&gt;While processing an array, the special variable &lt;tt&gt;{#}&lt;/tt&gt;
+ * will provide the current array index + 1 (starts at 1, not 0).&lt;/li&gt;
+ * &lt;/ul&gt;
+ * &lt;/p&gt;
+ * &lt;pre&gt;&lt;code&gt;
+&amp;lt;tpl &lt;b&gt;for&lt;/b&gt;=&quot;.&quot;&gt;...&amp;lt;/tpl&gt;       // loop through array at root node
+&amp;lt;tpl &lt;b&gt;for&lt;/b&gt;=&quot;foo&quot;&gt;...&amp;lt;/tpl&gt;     // loop through array at foo node
+&amp;lt;tpl &lt;b&gt;for&lt;/b&gt;=&quot;foo.bar&quot;&gt;...&amp;lt;/tpl&gt; // loop through array at foo.bar node
+ &lt;/code&gt;&lt;/pre&gt;
  * Using the sample data above:
- * <pre><code>
+ * &lt;pre&gt;&lt;code&gt;
 var tpl = new Ext.XTemplate(
-    '&lt;p>Kids: ',
-    '&lt;tpl <b>for</b>=".">',       // process the data.kids node
-        '&lt;p>{#}. {name}&lt;/p>',  // use current array index to autonumber
-    '&lt;/tpl>&lt;/p>'
+    '&amp;lt;p&gt;Kids: ',
+    '&amp;lt;tpl &lt;b&gt;for&lt;/b&gt;=&quot;.&quot;&gt;',       // process the data.kids node
+        '&amp;lt;p&gt;{#}. {name}&amp;lt;/p&gt;',  // use current array index to autonumber
+    '&amp;lt;/tpl&gt;&amp;lt;/p&gt;'
 );
 tpl.overwrite(panel.body, data.kids); // pass the kids property of the data object
- * </code></pre>
- * <p>An example illustrating how the <b><tt>for</tt></b> property can be leveraged
- * to access specified members of the provided data object to populate the template:</p>
- * <pre><code>
+ &lt;/code&gt;&lt;/pre&gt;
+ * &lt;p&gt;An example illustrating how the &lt;b&gt;&lt;tt&gt;for&lt;/tt&gt;&lt;/b&gt; property can be leveraged
+ * to access specified members of the provided data object to populate the template:&lt;/p&gt;
+ * &lt;pre&gt;&lt;code&gt;
 var tpl = new Ext.XTemplate(
-    '&lt;p>Name: {name}&lt;/p>',
-    '&lt;p>Title: {title}&lt;/p>',
-    '&lt;p>Company: {company}&lt;/p>',
-    '&lt;p>Kids: ',
-    '&lt;tpl <b>for="kids"</b>>',     // interrogate the kids property within the data
-        '&lt;p>{name}&lt;/p>',
-    '&lt;/tpl>&lt;/p>'
+    '&amp;lt;p&gt;Name: {name}&amp;lt;/p&gt;',
+    '&amp;lt;p&gt;Title: {title}&amp;lt;/p&gt;',
+    '&amp;lt;p&gt;Company: {company}&amp;lt;/p&gt;',
+    '&amp;lt;p&gt;Kids: ',
+    '&amp;lt;tpl &lt;b&gt;for=&quot;kids&quot;&lt;/b&gt;&gt;',     // interrogate the kids property within the data
+        '&amp;lt;p&gt;{name}&amp;lt;/p&gt;',
+    '&amp;lt;/tpl&gt;&amp;lt;/p&gt;'
 );
 tpl.overwrite(panel.body, data);  // pass the root node of the data object
- * </code></pre>
- * <p>Flat arrays that contain values (and not objects) can be auto-rendered
- * using the special <b><tt>{.}</tt></b> variable inside a loop.  This variable
- * will represent the value of the array at the current index:</p>
- * <pre><code>
+ &lt;/code&gt;&lt;/pre&gt;
+ * &lt;p&gt;Flat arrays that contain values (and not objects) can be auto-rendered
+ * using the special &lt;b&gt;&lt;tt&gt;{.}&lt;/tt&gt;&lt;/b&gt; variable inside a loop.  This variable
+ * will represent the value of the array at the current index:&lt;/p&gt;
+ * &lt;pre&gt;&lt;code&gt;
 var tpl = new Ext.XTemplate(
-    '&lt;p>{name}\&#39;s favorite beverages:&lt;/p>',
-    '&lt;tpl for="drinks">',
-       '&lt;div> - {.}&lt;/div>',
-    '&lt;/tpl>'
+    '&amp;lt;p&gt;{name}\&amp;#39;s favorite beverages:&amp;lt;/p&gt;',
+    '&amp;lt;tpl for=&quot;drinks&quot;&gt;',
+        '&amp;lt;div&gt; - {.}&amp;lt;/div&gt;',
+    '&amp;lt;/tpl&gt;'
 );
 tpl.overwrite(panel.body, data);
- * </code></pre>
- * <p>When processing a sub-template, for example while looping through a child array,
- * you can access the parent object's members via the <b><tt>parent</tt></b> object:</p>
- * <pre><code>
+ &lt;/code&gt;&lt;/pre&gt;
+ * &lt;p&gt;When processing a sub-template, for example while looping through a child array,
+ * you can access the parent object's members via the &lt;b&gt;&lt;tt&gt;parent&lt;/tt&gt;&lt;/b&gt; object:&lt;/p&gt;
+ * &lt;pre&gt;&lt;code&gt;
 var tpl = new Ext.XTemplate(
-    '&lt;p>Name: {name}&lt;/p>',
-    '&lt;p>Kids: ',
-    '&lt;tpl for="kids">',
-        '&lt;tpl if="age > 1">',
-            '&lt;p>{name}&lt;/p>',
-            '&lt;p>Dad: {<b>parent</b>.name}&lt;/p>',
-        '&lt;/tpl>',
-    '&lt;/tpl>&lt;/p>'
+    '&amp;lt;p&gt;Name: {name}&amp;lt;/p&gt;',
+    '&amp;lt;p&gt;Kids: ',
+    '&amp;lt;tpl for=&quot;kids&quot;&gt;',
+        '&amp;lt;tpl if=&quot;age &amp;amp;gt; 1&quot;&gt;',
+            '&amp;lt;p&gt;{name}&amp;lt;/p&gt;',
+            '&amp;lt;p&gt;Dad: {&lt;b&gt;parent&lt;/b&gt;.name}&amp;lt;/p&gt;',
+        '&amp;lt;/tpl&gt;',
+    '&amp;lt;/tpl&gt;&amp;lt;/p&gt;'
 );
 tpl.overwrite(panel.body, data);
- * </code></pre>
- * </div>
- * </li>
+ &lt;/code&gt;&lt;/pre&gt;
+ * &lt;/div&gt;
+ * &lt;/li&gt;
  *
  *
- * <li><b><u>Conditional processing with basic comparison operators</u></b>
- * <div class="sub-desc">
- * <p>The <b><tt>tpl</tt></b> tag and the <b><tt>if</tt></b> operator are used
+ * &lt;li&gt;&lt;b&gt;&lt;u&gt;Conditional processing with basic comparison operators&lt;/u&gt;&lt;/b&gt;
+ * &lt;div class=&quot;sub-desc&quot;&gt;
+ * &lt;p&gt;The &lt;b&gt;&lt;tt&gt;tpl&lt;/tt&gt;&lt;/b&gt; tag and the &lt;b&gt;&lt;tt&gt;if&lt;/tt&gt;&lt;/b&gt; operator are used
  * to provide conditional checks for deciding whether or not to render specific
- * parts of the template. Notes:<div class="sub-desc"><ul>
- * <li>Double quotes must be encoded if used within the conditional</li>
- * <li>There is no <tt>else</tt> operator &mdash; if needed, two opposite
- * <tt>if</tt> statements should be used.</li>
- * </ul></div>
- * <pre><code>
-&lt;tpl if="age &gt; 1 &amp;&amp; age &lt; 10">Child&lt;/tpl>
-&lt;tpl if="age >= 10 && age < 18">Teenager&lt;/tpl>
-&lt;tpl <b>if</b>="this.isGirl(name)">...&lt;/tpl>
-&lt;tpl <b>if</b>="id==\'download\'">...&lt;/tpl>
-&lt;tpl <b>if</b>="needsIcon">&lt;img src="{icon}" class="{iconCls}"/>&lt;/tpl>
+ * parts of the template. Notes:&lt;div class=&quot;sub-desc&quot;&gt;&lt;ul&gt;
+ * &lt;li&gt;Double quotes must be encoded if used within the conditional&lt;/li&gt;
+ * &lt;li&gt;There is no &lt;tt&gt;else&lt;/tt&gt; operator &amp;mdash; if needed, two opposite
+ * &lt;tt&gt;if&lt;/tt&gt; statements should be used.&lt;/li&gt;
+ * &lt;/ul&gt;&lt;/div&gt;
+ * &lt;pre&gt;&lt;code&gt;
+&amp;lt;tpl if=&quot;age &amp;gt; 1 &amp;amp;&amp;amp; age &amp;lt; 10&quot;&gt;Child&amp;lt;/tpl&gt;
+&amp;lt;tpl if=&quot;age &gt;= 10 &amp;&amp; age &lt; 18&quot;&gt;Teenager&amp;lt;/tpl&gt;
+&amp;lt;tpl &lt;b&gt;if&lt;/b&gt;=&quot;this.isGirl(name)&quot;&gt;...&amp;lt;/tpl&gt;
+&amp;lt;tpl &lt;b&gt;if&lt;/b&gt;=&quot;id==\'download\'&quot;&gt;...&amp;lt;/tpl&gt;
+&amp;lt;tpl &lt;b&gt;if&lt;/b&gt;=&quot;needsIcon&quot;&gt;&amp;lt;img src=&quot;{icon}&quot; class=&quot;{iconCls}&quot;/&gt;&amp;lt;/tpl&gt;
 // no good:
-&lt;tpl if="name == "Jack"">Hello&lt;/tpl>
-// encode &#34; if it is part of the condition, e.g.
-&lt;tpl if="name == &#38;quot;Jack&#38;quot;">Hello&lt;/tpl>
- * </code></pre>
+&amp;lt;tpl if=&quot;name == &quot;Tommy&quot;&quot;&gt;Hello&amp;lt;/tpl&gt;
+// encode &amp;#34; if it is part of the condition, e.g.
+&amp;lt;tpl if=&quot;name == &amp;#38;quot;Tommy&amp;#38;quot;&quot;&gt;Hello&amp;lt;/tpl&gt;
+ * &lt;/code&gt;&lt;/pre&gt;
  * Using the sample data above:
- * <pre><code>
+ * &lt;pre&gt;&lt;code&gt;
 var tpl = new Ext.XTemplate(
-    '&lt;p>Name: {name}&lt;/p>',
-    '&lt;p>Kids: ',
-    '&lt;tpl for="kids">',
-        '&lt;tpl if="age > 1">',
-            '&lt;p>{name}&lt;/p>',
-        '&lt;/tpl>',
-    '&lt;/tpl>&lt;/p>'
+    '&amp;lt;p&gt;Name: {name}&amp;lt;/p&gt;',
+    '&amp;lt;p&gt;Kids: ',
+    '&amp;lt;tpl for=&quot;kids&quot;&gt;',
+        '&amp;lt;tpl if=&quot;age &amp;amp;gt; 1&quot;&gt;',
+            '&amp;lt;p&gt;{name}&amp;lt;/p&gt;',
+        '&amp;lt;/tpl&gt;',
+    '&amp;lt;/tpl&gt;&amp;lt;/p&gt;'
 );
 tpl.overwrite(panel.body, data);
- * </code></pre>
- * </div>
- * </li>
+ &lt;/code&gt;&lt;/pre&gt;
+ * &lt;/div&gt;
+ * &lt;/li&gt;
  *
  *
- * <li><b><u>Basic math support</u></b>
- * <div class="sub-desc">
- * <p>The following basic math operators may be applied directly on numeric
- * data values:</p><pre>
+ * &lt;li&gt;&lt;b&gt;&lt;u&gt;Basic math support&lt;/u&gt;&lt;/b&gt;
+ * &lt;div class=&quot;sub-desc&quot;&gt;
+ * &lt;p&gt;The following basic math operators may be applied directly on numeric
+ * data values:&lt;/p&gt;&lt;pre&gt;
  * + - * /
- * </pre>
+ * &lt;/pre&gt;
  * For example:
- * <pre><code>
+ * &lt;pre&gt;&lt;code&gt;
 var tpl = new Ext.XTemplate(
-    '&lt;p>Name: {name}&lt;/p>',
-    '&lt;p>Kids: ',
-    '&lt;tpl for="kids">',
-        '&lt;tpl if="age &amp;gt; 1">',  // <-- Note that the &gt; is encoded
-            '&lt;p>{#}: {name}&lt;/p>',  // <-- Auto-number each item
-            '&lt;p>In 5 Years: {age+5}&lt;/p>',  // <-- Basic math
-            '&lt;p>Dad: {parent.name}&lt;/p>',
-        '&lt;/tpl>',
-    '&lt;/tpl>&lt;/p>'
+    '&amp;lt;p&gt;Name: {name}&amp;lt;/p&gt;',
+    '&amp;lt;p&gt;Kids: ',
+    '&amp;lt;tpl for=&quot;kids&quot;&gt;',
+        '&amp;lt;tpl if=&quot;age &amp;amp;gt; 1&quot;&gt;',  // &lt;-- Note that the &amp;gt; is encoded
+            '&amp;lt;p&gt;{#}: {name}&amp;lt;/p&gt;',  // &lt;-- Auto-number each item
+            '&amp;lt;p&gt;In 5 Years: {age+5}&amp;lt;/p&gt;',  // &lt;-- Basic math
+            '&amp;lt;p&gt;Dad: {parent.name}&amp;lt;/p&gt;',
+        '&amp;lt;/tpl&gt;',
+    '&amp;lt;/tpl&gt;&amp;lt;/p&gt;'
 );
 tpl.overwrite(panel.body, data);
-</code></pre>
- * </div>
- * </li>
+ &lt;/code&gt;&lt;/pre&gt;
+ * &lt;/div&gt;
+ * &lt;/li&gt;
  *
  *
- * <li><b><u>Execute arbitrary inline code with special built-in template variables</u></b>
- * <div class="sub-desc">
- * <p>Anything between <code>{[ ... ]}</code> is considered code to be executed
+ * &lt;li&gt;&lt;b&gt;&lt;u&gt;Execute arbitrary inline code with special built-in template variables&lt;/u&gt;&lt;/b&gt;
+ * &lt;div class=&quot;sub-desc&quot;&gt;
+ * &lt;p&gt;Anything between &lt;code&gt;{[ ... ]}&lt;/code&gt; is considered code to be executed
  * in the scope of the template. There are some special variables available in that code:
- * <ul>
- * <li><b><tt>values</tt></b>: The values in the current scope. If you are using
- * scope changing sub-templates, you can change what <tt>values</tt> is.</li>
- * <li><b><tt>parent</tt></b>: The scope (values) of the ancestor template.</li>
- * <li><b><tt>xindex</tt></b>: If you are in a looping template, the index of the
- * loop you are in (1-based).</li>
- * <li><b><tt>xcount</tt></b>: If you are in a looping template, the total length
- * of the array you are looping.</li>
- * <li><b><tt>fm</tt></b>: An alias for <tt>Ext.util.Format</tt>.</li>
- * </ul>
+ * &lt;ul&gt;
+ * &lt;li&gt;&lt;b&gt;&lt;tt&gt;values&lt;/tt&gt;&lt;/b&gt;: The values in the current scope. If you are using
+ * scope changing sub-templates, you can change what &lt;tt&gt;values&lt;/tt&gt; is.&lt;/li&gt;
+ * &lt;li&gt;&lt;b&gt;&lt;tt&gt;parent&lt;/tt&gt;&lt;/b&gt;: The scope (values) of the ancestor template.&lt;/li&gt;
+ * &lt;li&gt;&lt;b&gt;&lt;tt&gt;xindex&lt;/tt&gt;&lt;/b&gt;: If you are in a looping template, the index of the
+ * loop you are in (1-based).&lt;/li&gt;
+ * &lt;li&gt;&lt;b&gt;&lt;tt&gt;xcount&lt;/tt&gt;&lt;/b&gt;: If you are in a looping template, the total length
+ * of the array you are looping.&lt;/li&gt;
+ * &lt;/ul&gt;
  * This example demonstrates basic row striping using an inline code block and the
- * <tt>xindex</tt> variable:</p>
- * <pre><code>
+ * &lt;tt&gt;xindex&lt;/tt&gt; variable:&lt;/p&gt;
+ * &lt;pre&gt;&lt;code&gt;
 var tpl = new Ext.XTemplate(
-    '&lt;p>Name: {name}&lt;/p>',
-    '&lt;p>Company: {[values.company.toUpperCase() + ", " + values.title]}&lt;/p>',
-    '&lt;p>Kids: ',
-    '&lt;tpl for="kids">',
-       '&lt;div class="{[xindex % 2 === 0 ? "even" : "odd"]}">',
+    '&amp;lt;p&gt;Name: {name}&amp;lt;/p&gt;',
+    '&amp;lt;p&gt;Company: {[values.company.toUpperCase() + &quot;, &quot; + values.title]}&amp;lt;/p&gt;',
+    '&amp;lt;p&gt;Kids: ',
+    '&amp;lt;tpl for=&quot;kids&quot;&gt;',
+        '&amp;lt;div class=&quot;{[xindex % 2 === 0 ? &quot;even&quot; : &quot;odd&quot;]}&quot;&gt;',
         '{name}',
-        '&lt;/div>',
-    '&lt;/tpl>&lt;/p>'
-);
+        '&amp;lt;/div&gt;',
+    '&amp;lt;/tpl&gt;&amp;lt;/p&gt;'
+ );
 tpl.overwrite(panel.body, data);
- * </code></pre>
- * </div>
- * </li>
+ &lt;/code&gt;&lt;/pre&gt;
+ * &lt;/div&gt;
+ * &lt;/li&gt;
  *
- * <li><b><u>Template member functions</u></b>
- * <div class="sub-desc">
- * <p>One or more member functions can be specified in a configuration
- * object passed into the XTemplate constructor for more complex processing:</p>
- * <pre><code>
+ * &lt;li&gt;&lt;b&gt;&lt;u&gt;Template member functions&lt;/u&gt;&lt;/b&gt;
+ * &lt;div class=&quot;sub-desc&quot;&gt;
+ * &lt;p&gt;One or more member functions can be specified in a configuration
+ * object passed into the XTemplate constructor for more complex processing:&lt;/p&gt;
+ * &lt;pre&gt;&lt;code&gt;
 var tpl = new Ext.XTemplate(
-    '&lt;p>Name: {name}&lt;/p>',
-    '&lt;p>Kids: ',
-    '&lt;tpl for="kids">',
-        '&lt;tpl if="this.isGirl(name)">',
-            '&lt;p>Girl: {name} - {age}&lt;/p>',
-        '&lt;/tpl>',
-        // use opposite if statement to simulate 'else' processing:
-        '&lt;tpl if="this.isGirl(name) == false">',
-            '&lt;p>Boy: {name} - {age}&lt;/p>',
-        '&lt;/tpl>',
-        '&lt;tpl if="this.isBaby(age)">',
-            '&lt;p>{name} is a baby!&lt;/p>',
-        '&lt;/tpl>',
-    '&lt;/tpl>&lt;/p>',
+    '&amp;lt;p&gt;Name: {name}&amp;lt;/p&gt;',
+    '&amp;lt;p&gt;Kids: ',
+    '&amp;lt;tpl for=&quot;kids&quot;&gt;',
+        '&amp;lt;tpl if=&quot;this.isGirl(name)&quot;&gt;',
+            '&amp;lt;p&gt;Girl: {name} - {age}&amp;lt;/p&gt;',
+        '&amp;lt;/tpl&gt;',
+         // use opposite if statement to simulate 'else' processing:
+        '&amp;lt;tpl if=&quot;this.isGirl(name) == false&quot;&gt;',
+            '&amp;lt;p&gt;Boy: {name} - {age}&amp;lt;/p&gt;',
+        '&amp;lt;/tpl&gt;',
+        '&amp;lt;tpl if=&quot;this.isBaby(age)&quot;&gt;',
+            '&amp;lt;p&gt;{name} is a baby!&amp;lt;/p&gt;',
+        '&amp;lt;/tpl&gt;',
+    '&amp;lt;/tpl&gt;&amp;lt;/p&gt;',
     {
         // XTemplate configuration:
         compiled: true,
-        disableFormats: true,
         // member functions:
         isGirl: function(name){
-            return name == 'Sara Grace';
+           return name == 'Sara Grace';
         },
         isBaby: function(age){
-            return age < 1;
+           return age &lt; 1;
         }
     }
 );
 tpl.overwrite(panel.body, data);
- * </code></pre>
- * </div>
- * </li>
+ &lt;/code&gt;&lt;/pre&gt;
+ * &lt;/div&gt;
+ * &lt;/li&gt;
  *
- * </ul></div>
+ * &lt;/ul&gt;&lt;/div&gt;
  *
  * @param {Mixed} config
  */
-Ext.XTemplate = function(){
-    Ext.XTemplate.superclass.constructor.apply(this, arguments);
 
-    var me = this,
-        s = me.html,
-        re = /<tpl\b[^>]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/,
-        nameRe = /^<tpl\b[^>]*?for="(.*?)"/,
-        ifRe = /^<tpl\b[^>]*?if="(.*?)"/,
-        execRe = /^<tpl\b[^>]*?exec="(.*?)"/,
-        m,
-        id = 0,
-        tpls = [],
-        VALUES = 'values',
-        PARENT = 'parent',
-        XINDEX = 'xindex',
-        XCOUNT = 'xcount',
-        RETURN = 'return ',
-        WITHVALUES = 'with(values){ ';
+Ext.define('Ext.XTemplate', {
 
-    s = ['<tpl>', s, '</tpl>'].join('');
+    /* Begin Definitions */
 
-    while((m = s.match(re))){
-        var m2 = m[0].match(nameRe),
-            m3 = m[0].match(ifRe),
-            m4 = m[0].match(execRe),
-            exp = null,
-            fn = null,
-            exec = null,
-            name = m2 && m2[1] ? m2[1] : '';
+    extend: 'Ext.Template',
 
-       if (m3) {
-           exp = m3 && m3[1] ? m3[1] : null;
-           if(exp){
-               fn = new Function(VALUES, PARENT, XINDEX, XCOUNT, WITHVALUES + RETURN +(Ext.util.Format.htmlDecode(exp))+'; }');
-           }
-       }
-       if (m4) {
-           exp = m4 && m4[1] ? m4[1] : null;
-           if(exp){
-               exec = new Function(VALUES, PARENT, XINDEX, XCOUNT, WITHVALUES +(Ext.util.Format.htmlDecode(exp))+'; }');
-           }
-       }
-       if(name){
-           switch(name){
-               case '.': name = new Function(VALUES, PARENT, WITHVALUES + RETURN + VALUES + '; }'); break;
-               case '..': name = new Function(VALUES, PARENT, WITHVALUES + RETURN + PARENT + '; }'); break;
-               default: name = new Function(VALUES, PARENT, WITHVALUES + RETURN + name + '; }');
-           }
-       }
-       tpls.push({
-            id: id,
-            target: name,
-            exec: exec,
-            test: fn,
-            body: m[1]||''
-        });
-       s = s.replace(m[0], '{xtpl'+ id + '}');
-       ++id;
-    }
-    for(var i = tpls.length-1; i >= 0; --i){
-        me.compileTpl(tpls[i]);
-    }
-    me.master = tpls[tpls.length-1];
-    me.tpls = tpls;
-};
-Ext.extend(Ext.XTemplate, Ext.Template, {
-    // private
-    re : /\{([\w-\.\#]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?(\s?[\+\-\*\\]\s?[\d\.\+\-\*\\\(\)]+)?\}/g,
-    // private
-    codeRe : /\{\[((?:\\\]|.|\n)*?)\]\}/g,
+    statics: {
+<span id='Ext-XTemplate-method-from'>        /**
+</span>         * Creates a template from the passed element's value (&lt;i&gt;display:none&lt;/i&gt; textarea, preferred) or innerHTML.
+         * @param {String/HTMLElement} el A DOM element or its id
+         * @return {Ext.Template} The created template
+         * @static
+         */
+        from: function(el, config) {
+            el = Ext.getDom(el);
+            return new this(el.value || el.innerHTML, config || {});
+        }
+    },
+
+    /* End Definitions */
+
+    argsRe: /&lt;tpl\b[^&gt;]*&gt;((?:(?=([^&lt;]+))\2|&lt;(?!tpl\b[^&gt;]*&gt;))*?)&lt;\/tpl&gt;/,
+    nameRe: /^&lt;tpl\b[^&gt;]*?for=&quot;(.*?)&quot;/,
+    ifRe: /^&lt;tpl\b[^&gt;]*?if=&quot;(.*?)&quot;/,
+    execRe: /^&lt;tpl\b[^&gt;]*?exec=&quot;(.*?)&quot;/,
+    constructor: function() {
+        this.callParent(arguments);
 
-    // private
-    applySubTemplate : function(id, values, parent, xindex, xcount){
         var me = this,
-            len,
-            t = me.tpls[id],
-            vs,
-            buf = [];
-        if ((t.test && !t.test.call(me, values, parent, xindex, xcount)) ||
-            (t.exec && t.exec.call(me, values, parent, xindex, xcount))) {
-            return '';
-        }
-        vs = t.target ? t.target.call(me, values, parent) : values;
-        len = vs.length;
-        parent = t.target ? values : parent;
-        if(t.target && Ext.isArray(vs)){
-            for(var i = 0, len = vs.length; i < len; i++){
-                buf[buf.length] = t.compiled.call(me, vs[i], parent, i+1, len);
+            html = me.html,
+            argsRe = me.argsRe,
+            nameRe = me.nameRe,
+            ifRe = me.ifRe,
+            execRe = me.execRe,
+            id = 0,
+            tpls = [],
+            VALUES = 'values',
+            PARENT = 'parent',
+            XINDEX = 'xindex',
+            XCOUNT = 'xcount',
+            RETURN = 'return ',
+            WITHVALUES = 'with(values){ ',
+            m, matchName, matchIf, matchExec, exp, fn, exec, name, i;
+
+        html = ['&lt;tpl&gt;', html, '&lt;/tpl&gt;'].join('');
+
+        while ((m = html.match(argsRe))) {
+            exp = null;
+            fn = null;
+            exec = null;
+            matchName = m[0].match(nameRe);
+            matchIf = m[0].match(ifRe);
+            matchExec = m[0].match(execRe);
+
+            exp = matchIf ? matchIf[1] : null;
+            if (exp) {
+                fn = Ext.functionFactory(VALUES, PARENT, XINDEX, XCOUNT, WITHVALUES + 'try{' + RETURN + Ext.String.htmlDecode(exp) + ';}catch(e){return;}}');
+            }
+
+            exp = matchExec ? matchExec[1] : null;
+            if (exp) {
+                exec = Ext.functionFactory(VALUES, PARENT, XINDEX, XCOUNT, WITHVALUES + Ext.String.htmlDecode(exp) + ';}');
             }
-            return buf.join('');
+
+            name = matchName ? matchName[1] : null;
+            if (name) {
+                if (name === '.') {
+                    name = VALUES;
+                } else if (name === '..') {
+                    name = PARENT;
+                }
+                name = Ext.functionFactory(VALUES, PARENT, 'try{' + WITHVALUES + RETURN + name + ';}}catch(e){return;}');
+            }
+
+            tpls.push({
+                id: id,
+                target: name,
+                exec: exec,
+                test: fn,
+                body: m[1] || ''
+            });
+
+            html = html.replace(m[0], '{xtpl' + id + '}');
+            id = id + 1;
+        }
+
+        for (i = tpls.length - 1; i &gt;= 0; --i) {
+            me.compileTpl(tpls[i]);
         }
-        return t.compiled.call(me, vs, parent, xindex, xcount);
+        me.master = tpls[tpls.length - 1];
+        me.tpls = tpls;
     },
 
-    // private
-    compileTpl : function(tpl){
+    // @private
+    applySubTemplate: function(id, values, parent, xindex, xcount) {
+        var me = this, t = me.tpls[id];
+        return t.compiled.call(me, values, parent, xindex, xcount);
+    },
+<span id='Ext-XTemplate-cfg-codeRe'>    /**
+</span>     * @cfg {RegExp} codeRe The regular expression used to match code variables (default: matches &lt;tt&gt;{[expression]}&lt;/tt&gt;).
+     */
+    codeRe: /\{\[((?:\\\]|.|\n)*?)\]\}/g,
+
+    re: /\{([\w-\.\#]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?(\s?[\+\-\*\/]\s?[\d\.\+\-\*\/\(\)]+)?\}/g,
+
+    // @private
+    compileTpl: function(tpl) {
         var fm = Ext.util.Format,
-            useF = this.disableFormats !== true,
-            sep = Ext.isGecko ? "+" : ",",
-            body;
+            me = this,
+            useFormat = me.disableFormats !== true,
+            body, bodyReturn, evaluatedFn;
 
-        function fn(m, name, format, args, math){
-            if(name.substr(0, 4) == 'xtpl'){
-                return "'"+ sep +'this.applySubTemplate('+name.substr(4)+', values, parent, xindex, xcount)'+sep+"'";
-            }
+        function fn(m, name, format, args, math) {
             var v;
-            if(name === '.'){
-                v = 'values';
-            }else if(name === '#'){
+            // name is what is inside the {}
+            // Name begins with xtpl, use a Sub Template
+            if (name.substr(0, 4) == 'xtpl') {
+                return &quot;',this.applySubTemplate(&quot; + name.substr(4) + &quot;, values, parent, xindex, xcount),'&quot;;
+            }
+            // name = &quot;.&quot; - Just use the values object.
+            if (name == '.') {
+                // filter to not include arrays/objects/nulls
+                v = 'Ext.Array.indexOf([&quot;string&quot;, &quot;number&quot;, &quot;boolean&quot;], typeof values) &gt; -1 || Ext.isDate(values) ? values : &quot;&quot;';
+            }
+
+            // name = &quot;#&quot; - Use the xindex
+            else if (name == '#') {
                 v = 'xindex';
-            }else if(name.indexOf('.') != -1){
+            }
+            else if (name.substr(0, 7) == &quot;parent.&quot;) {
                 v = name;
-            }else{
-                v = "values['" + name + "']";
             }
-            if(math){
+            // name has a . in it - Use object literal notation, starting from values
+            else if (name.indexOf('.') != -1) {
+                v = &quot;values.&quot; + name;
+            }
+
+            // name is a property of values
+            else {
+                v = &quot;values['&quot; + name + &quot;']&quot;;
+            }
+            if (math) {
                 v = '(' + v + math + ')';
             }
-            if (format && useF) {
-                args = args ? ',' + args : "";
-                if(format.substr(0, 5) != "this."){
-                    format = "fm." + format + '(';
-                }else{
-                    format = 'this.call("'+ format.substr(5) + '", ';
-                    args = ", values";
+            if (format &amp;&amp; useFormat) {
+                args = args ? ',' + args : &quot;&quot;;
+                if (format.substr(0, 5) != &quot;this.&quot;) {
+                    format = &quot;fm.&quot; + format + '(';
                 }
-            } else {
-                args= ''; format = "("+v+" === undefined ? '' : ";
+                else {
+                    format = 'this.' + format.substr(5) + '(';
+                }
+            }
+            else {
+                args = '';
+                format = &quot;(&quot; + v + &quot; === undefined ? '' : &quot;;
             }
-            return "'"+ sep + format + v + args + ")"+sep+"'";
+            return &quot;',&quot; + format + v + args + &quot;),'&quot;;
         }
 
-        function codeFn(m, code){
+        function codeFn(m, code) {
             // Single quotes get escaped when the template is compiled, however we want to undo this when running code.
-            return "'" + sep + '(' + code.replace(/\\'/g, "'") + ')' + sep + "'";
+            return &quot;',(&quot; + code.replace(me.compileARe, &quot;'&quot;) + &quot;),'&quot;;
         }
 
-        // branched to use + in gecko and [].join() in others
-        if(Ext.isGecko){
-            body = "tpl.compiled = function(values, parent, xindex, xcount){ return '" +
-                   tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn).replace(this.codeRe, codeFn) +
-                    "';};";
-        }else{
-            body = ["tpl.compiled = function(values, parent, xindex, xcount){ return ['"];
-            body.push(tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn).replace(this.codeRe, codeFn));
-            body.push("'].join('');};");
-            body = body.join('');
-        }
+        bodyReturn = tpl.body.replace(me.compileBRe, '\\n').replace(me.compileCRe, &quot;\\'&quot;).replace(me.re, fn).replace(me.codeRe, codeFn);
+        body = &quot;evaluatedFn = function(values, parent, xindex, xcount){return ['&quot; + bodyReturn + &quot;'].join('');};&quot;;
         eval(body);
+
+        tpl.compiled = function(values, parent, xindex, xcount) {
+            var vs,
+                length,
+                buffer,
+                i;
+
+            if (tpl.test &amp;&amp; !tpl.test.call(me, values, parent, xindex, xcount)) {
+                return '';
+            }
+
+            vs = tpl.target ? tpl.target.call(me, values, parent) : values;
+            if (!vs) {
+               return '';
+            }
+
+            parent = tpl.target ? values : parent;
+            if (tpl.target &amp;&amp; Ext.isArray(vs)) {
+                buffer = [];
+                length = vs.length;
+                if (tpl.exec) {
+                    for (i = 0; i &lt; length; i++) {
+                        buffer[buffer.length] = evaluatedFn.call(me, vs[i], parent, i + 1, length);
+                        tpl.exec.call(me, vs[i], parent, i + 1, length);
+                    }
+                } else {
+                    for (i = 0; i &lt; length; i++) {
+                        buffer[buffer.length] = evaluatedFn.call(me, vs[i], parent, i + 1, length);
+                    }
+                }
+                return buffer.join('');
+            }
+
+            if (tpl.exec) {
+                tpl.exec.call(me, vs, parent, xindex, xcount);
+            }
+            return evaluatedFn.call(me, vs, parent, xindex, xcount);
+        };
+
         return this;
     },
 
-    <div id="method-Ext.XTemplate-applyTemplate"></div>/**
-     * Returns an HTML fragment of this template with the specified values applied.
+<span id='Ext-XTemplate-method-applyTemplate'>    /**
+</span>     * Returns an HTML fragment of this template with the specified values applied.
      * @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
      * @return {String} The HTML fragment
      */
-    applyTemplate : function(values){
+    applyTemplate: function(values) {
         return this.master.compiled.call(this, values, {}, 1, 1);
     },
 
-    <div id="method-Ext.XTemplate-compile"></div>/**
-     * Compile the template to a function for optimized performance.  Recommended if the template will be used frequently.
+<span id='Ext-XTemplate-method-compile'>    /**
+</span>     * Compile the template to a function for optimized performance.  Recommended if the template will be used frequently.
      * @return {Function} The compiled function
      */
-    compile : function(){return this;}
-
-    <div id="prop-Ext.XTemplate-re"></div>/**
-     * @property re
-     * @hide
-     */
-    <div id="prop-Ext.XTemplate-disableFormats"></div>/**
-     * @property disableFormats
-     * @hide
-     */
-    <div id="method-Ext.XTemplate-set"></div>/**
-     * @method set
-     * @hide
+    compile: function() {
+        return this;
+    }
+}, function() {
+<span id='Ext-XTemplate-method-apply'>    /**
+</span>     * Alias for {@link #applyTemplate}
+     * Returns an HTML fragment of this template with the specified values applied.
+     * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
+     * @return {String} The HTML fragment
+     * @member Ext.XTemplate
+     * @method apply
      */
-
+    this.createAlias('apply', 'applyTemplate');
 });
-<div id="method-Ext.XTemplate-apply"></div>/**
- * Alias for {@link #applyTemplate}
- * Returns an HTML fragment of this template with the specified values applied.
- * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
- * @return {String} The HTML fragment
- * @member Ext.XTemplate
- * @method apply
- */
-Ext.XTemplate.prototype.apply = Ext.XTemplate.prototype.applyTemplate;
-
-<div id="method-Ext.XTemplate-XTemplate.from"></div>/**
- * Creates a template from the passed element's value (<i>display:none</i> textarea, preferred) or innerHTML.
- * @param {String/HTMLElement} el A DOM element or its id
- * @return {Ext.Template} The created template
- * @static
- */
-Ext.XTemplate.from = function(el){
-    el = Ext.getDom(el);
-    return new Ext.XTemplate(el.value || el.innerHTML);
-};
-</pre>    
-</body>
-</html>
\ No newline at end of file
+</pre></pre></body></html>
\ No newline at end of file