[ALOY-630] Use base xml files for views
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Medium |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | Alloy, xml |
Reporter | Daniel Sefton |
Assignee | Unknown |
Created | 2013-04-19T17:27:22.000+0000 |
Updated | 2018-03-07T22:26:01.000+0000 |
Description
Views should be able to include other views as a template and override. In the example below I use the id tag to identify which section to override. a simple example is as follows. base.xml
<Alloy>
<Window id='win' class="container" onClose='onClose'>
<View id="menu" onClick="showhidemenu">
<Require src="menu_top" id="menucnt"/>
</View>
<View id="main">
<View id="iconBar" width="100%">
<ImageView id="menubtn" onClick="showhidemenu"></ImageView>
<Label class="title" id="title">Some title</Label>
</View>
<View id="grayLine"></View>
<View id="mainList">
some custom content
</View>
</View>
</Window>
</Alloy>
mywin.xml
<Extends src='base.xml'/>
<View id="menu" onClick="closeWindow">
<Require src="menu_new" id="menucnt"/>
</View>
<View id="mainList">
some new content
</View>
Comments
- John C. Bland II 2013-04-19 +1 for the concept. Open to the implementation.
- Tony Lukasavage 2013-04-22
Would the views added to the
just be appended to its children? - John C. Bland II 2013-04-22
I think a layout system would be better. Extending a view seems it can get a bit confusing. Without layouts, you could easily do something like:
... - Tony Lukasavage 2013-04-22
John, I'm not sure I'm following. Also, we couldn't use
layout
since that is already in use by the Titanium API. - John C. Bland II 2013-04-22
No worries on 'layout'. Consider all of that pseudo.
One of the best templating engines I've seen is Rails and that's what that comment was loosely based on: http://guides.rubyonrails.org/layouts_and_rendering.html. Basically a way to fill out a custom layout/template then fill it in with views that implement it.
It is basically a preference from having dealt with this many days doing interactive and backend work. Extending can get hairy (hence the love of composition of inheritance now-a-days; another story though). :-D
Here is another, fuller, example of implementing a template/layout.
mytemplate.xml
someview.xml<Window> <View ...> <Require src="menu_new" id="menucnt /> <Yield id="navigation" /> </View> <View> <Yield id="body" /> </View> </Window>
<View template="mytemplate"> <ContentFor="navigation"> <!-- extra nav view specific stuff here ---> </ContentFor> <ContentFor="body"> <!-- extra body view specific stuff here ---> </ContentFor> </View>
- Mitch Duitz 2013-04-23
Can the
also include views, such that if the is not defined the yield would be the default view? - John C. Bland II 2013-04-23
Yep.
would be anything not wrapped in a ContentFor. (thx for pointing that out)