Where should a new XTemplate be defined with Sencha Touch 2?

I am building my first application with ST2 and started by creating the application described in Getting Started with Sencha Touch 2 , then taking that and trying it out to modify it to suit my own needs. The demo application has a DataView list in which each item can be used to display the corresponding detail page.

In this app, the content on the detail pages is pulled dynamically and does not require any particular style or layout. However, for my own detail pages, I need to use a template or XTemplate to style and place my data.

I can't figure out where I should define the template (i.e. var myTpl = new Ext.XTemplate (...)) - In the controller in the model?

Any guidance on this front would be greatly appreciated.

+3


source to share


1 answer


It depends on where you want to use the XTemplate. If this will only ever be used in one view then just define the xtemplate when you define the view.

{
   xtype : 'view',
   tpl : new XTemplate('<div></div>...')
}

      

If you are going to use it in multiple views, you can create a class for the sole purpose of sharing templates.



Ext.define('MyApp.util.SharedTemplates', {
    statics : {
         sharedTemplate1 : new XTemplate('<div></div>')
    }

});

      

This way the template is only compiled once and reused.

+3


source







All Articles