[Dev] Block templates and parcel.xml

Morgen Sagen morgen at osafoundation.org
Fri Jun 25 20:02:56 PDT 2004


As you may have noticed from today's check-ins, you can now copy entire 
Block (or any item) hierarchies within parcel.xml.  So Donn, you can be 
the guinea pig for this.  Create a tree of Block items somewhere to use 
as a template, and then whenever you want a copy of that template, you 
make a reference to the top Item of that template, but also specify 
copy="<nameOfCopy>".  For example, assuming "me" is the xmlns prefix 
for this parcel, and the default namespace is the core schema:

<!-- Define a template with a Block and two child Blocks -->

<Block itsName="TemplateParent">
    <childrenBlocks ref="me:TemplateChild0"/>
    <childrenBlocks ref="me:TemplateChild1"/>
<Block itsName="TemplateChild0" />
<Block itsName="TemplateChild1" />


<!-- Make use of the template -->

<Block itsName="AnotherBlock">
     <childrenBlocks ref="me:TemplateParent" copy="CopiedTemplate" />
</Block>


AnotherBlock will get a child item named CopiedTemplate (identical to 
the TemplateParent item), which will in turn have two children (whose 
names are autogenerated by the repository).  The repository determines 
how "deep" to copy by examining each items' attributes and traversing 
those whose copyPolicy is "cascade".  The childrenBlocks attribute now 
has its copyPolicy set to cascade.  Also, it's okay to refer to a 
template within the same file as the template, as long as the reference 
comes after the template definition.

Thanks to Andi for implementing deep Item copying in the repository for 
us!

~morgen




More information about the Dev mailing list