The document discusses advanced templates in Sencha Ext JS. It describes how templates combined with data can generate HTML. Templates provide control statements, conditions, loops and formatting. XTemplates were introduced in Ext JS 2.0 and 3.0 for easier and faster template writing. Multiple templates can be defined and templates are compiled to Java for performance. The template language supports variable scoping, replacement, and custom formatters. Templates can also be nested.
9. Multiple Templates
public interface DataRenderer extends XTemplates {
@XTemplate("<p>Name: {data.name}</p><p>Company: {data.company}</p>
<p>Location: {data.location}</p>")
public SafeHtml render(Person data);
@XTemplate(source = "template.html")
public SafeHtml renderTemplate(Person data);
}
Wednesday, November 2, 2011
10. 3.0 Compiled Templates
Template compiled to Java with SafeHtmlTemplates
Paths translated to getters, or error
Compiler can optimize Java to JavaScript
Returns SafeHtml objects
Wednesday, November 2, 2011
12. Control Statements
<tpl if="condition">
contents
</tpl>
<tpl for="collection">
properties of item
</tpl>
Wednesday, November 2, 2011
13. Variable Scoping
Scoped like JavaScript, not Java
Loops can reuse variable names
If only one argument to template, no need to name it
parent refers to previously scoped object
# is a 1-indexed current position in collection
Wednesday, November 2, 2011