[ALOY-630] Use base xml files for views

GitHub Issuen/a
TypeNew Feature
Affected Version/sn/a
Fix Version/sn/a
LabelsAlloy, xml
ReporterDaniel Sefton


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
  <Window id='win' class="container"  onClose='onClose'>
    <View id="menu" onClick="showhidemenu">
      <Require src="menu_top" id="menucnt"/>
    <View id="main">
      <View id="iconBar" width="100%">
         <ImageView id="menubtn" onClick="showhidemenu"></ImageView>
         <Label class="title" id="title">Some title</Label>
      <View id="grayLine"></View>			
      <View id="mainList">
         some custom content		
<Extends src='base.xml'/>
<View id="menu" onClick="closeWindow">
      <Require src="menu_new" id="menucnt"/>
<View id="mainList">
  some new content


  1. John C. Bland II 2013-04-19 +1 for the concept. Open to the implementation.
  2. Tony Lukasavage 2013-04-22 Would the views added to the just be appended to its children?
  3. 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: Maybe even in the root of it allow you to set the layout: ...
  4. 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.
  5. 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
            <View ...>
                 <Require src="menu_new" id="menucnt />
                 <Yield id="navigation" />
                 <Yield id="body" />
       <View template="mytemplate">
                 <!-- extra nav view specific stuff here --->
                 <!-- extra body view specific stuff here --->
  6. Mitch Duitz 2013-04-23 Can the also include views, such that if the is not defined the yield would be the default view?
  7. John C. Bland II 2013-04-23 Yep. would be anything not wrapped in a ContentFor. (thx for pointing that out)

JSON Source