Alien-Web-ExtJS-V3
view release on metacpan or search on metacpan
share/docs/source/XTemplate.html view on Meta::CPAN
&lt;tpl <b>for</b>="foo.bar">...&lt;/tpl> // loop through array at foo.bar node
* </code></pre>
* Using the sample data above:
* <pre><code>
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>'
);
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>
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>'
);
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>
var tpl = new Ext.XTemplate(
'&lt;p>{name}\&#39;s favorite beverages:&lt;/p>',
'&lt;tpl for="drinks">',
'&lt;div> - {.}&lt;/div>',
'&lt;/tpl>'
);
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>
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>'
);
tpl.overwrite(panel.body, data);
* </code></pre>
* </div>
* </li>
*
*
* <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
* 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>
// 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>
* Using the sample data above:
* <pre><code>
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>'
);
tpl.overwrite(panel.body, data);
* </code></pre>
* </div>
* </li>
*
*
* <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>
* + - * /
* </pre>
* For example:
* <pre><code>
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>'
);
tpl.overwrite(panel.body, data);
</code></pre>
* </div>
* </li>
*
*
* <li><b><u>Execute arbitrary inline code with special built-in template variables</u></b>
* <div class="sub-desc">
( run in 0.332 second using v1.01-cache-2.11-cpan-119454b85a5 )