Titanium JIRA Archive
Alloy (ALOY)

[ALOY-630] Use base xml files for views

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
LabelsAlloy, xml
ReporterDaniel Sefton
AssigneeUnknown
Created2013-04-19T17:27:22.000+0000
Updated2018-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

  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
       <Window>
            <View ...>
                 <Require src="menu_new" id="menucnt />
                 <Yield id="navigation" />
            </View>
       
            <View>
                 <Yield id="body" />
            </View>
       </Window>
       
    someview.xml
       <View template="mytemplate">
            <ContentFor="navigation">
                 <!-- extra nav view specific stuff here --->
            </ContentFor>
       
            <ContentFor="body">
                 <!-- extra body view specific stuff here --->
            </ContentFor>
       </View>
       
  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