-
13 Mar 2012 1:16 PM #1
Answered: Where should a new XTemplate be defined?
Answered: Where should a new XTemplate be defined?
I am building my first app with ST2 and began by building the app outlined in Getting Started with Sencha Touch 2 and then taking that and trying to modify it so it met my own needs. The demo app has a DataView List where each element can be tapped to reveal a corresponding detail page.
In that app the content on the detail pages is being pulled in dynamically and does not need to be styled or arranged much. However, for my own detail pages I need to use a Template or XTemplate to style and position my data.
I can't seem to figure out where I should define the template (ie, var myTpl = new Ext.XTemplate(...)) —In the controller, in the model?
Any guidance on this front would be much appreciated.
-
Best Answer Posted by mrsunshine
you can define it in the view
and in you controller you can set the data for the viewCode:{ xtype: 'container', tpl: new Ext.XTemplate(...) ... }
for exampleCode:view.setData(record.data)
-
13 Mar 2012 3:27 PM #2Sencha - Training Team
- Join Date
- Sep 2008
- Location
- Germany - Darmstadt
- Posts
- 682
- Vote Rating
- 10
- Answers
- 21
you can define it in the view
and in you controller you can set the data for the viewCode:{ xtype: 'container', tpl: new Ext.XTemplate(...) ... }
for exampleCode:view.setData(record.data)
trainings / workshops / consulting: Sencha Touch / Ext JS
Profile on SenchaDevs
www: http://www.nils-dehl.de
twitter: nilsdehl
meetup: Sencha Touch / Ext JS Meetup Frankfurt
videos: http://vimeo.com/album/1621422
conference photos: http://www.flickr.com/photos/nils-dehl/
-
13 Mar 2012 6:32 PM #3
Thanks for your quick reply!
I get that I can define the XTemplate directly after tpl:, but I would like to be able to do is to define it as a separate object, so that I can then do tpl : xTemplateName. Do you happen to have any thoughts on this?
-
14 Mar 2012 12:46 PM #4Sencha - Training Team
- Join Date
- Sep 2008
- Location
- Germany - Darmstadt
- Posts
- 682
- Vote Rating
- 10
- Answers
- 21
you could also have a template object which manage (singelton manager obeject) your templates and
than just call Config.getTemplateXyz();trainings / workshops / consulting: Sencha Touch / Ext JS
Profile on SenchaDevs
www: http://www.nils-dehl.de
twitter: nilsdehl
meetup: Sencha Touch / Ext JS Meetup Frankfurt
videos: http://vimeo.com/album/1621422
conference photos: http://www.flickr.com/photos/nils-dehl/
-
14 Mar 2012 3:26 PM #5
Personally, I define my templates in their own classes. When I want to reference them in the view, I do something like so.
I don't know of too many reasons why a controller would have to know about the existence of a template unless you had some funky template changing going on.Code:config:{ align:'start', tpl:Ext.create('MyApp.view.templates.BiscuitTemplate') },


Reply With Quote