Sometimes it is useful to have a structured page with, say, a structured body. Tipically, there is a main layout (for example, the "classic" layout) and the body is made of certain number of sections. In this case, nesting a definition (the one for the body) inside another definition (the main layout) can be useful.
Tiles supports nesting definitions natively. The inner definition must be put as an attribute value of a template. For example:
<definition name="myapp.homepage.body" template="/layouts/three_rows.jsp"> <put-attribute name="one" value="/tiles/headlines.jsp" /> <put-attribute name="two" value="/tiles/topics.jsp" /> <put-attribute name="one" value="/tiles/comments.jsp" /> </definition> <definition name="myapp.homepage" template="/layouts/classic.jsp"> <put-attribute name="title" value="Tiles tutorial homepage" /> <put-attribute name="header" value="/tiles/banner.jsp" /> <put-attribute name="menu" value="/tiles/common_menu.jsp" /> <put-attribute name="body" value="myapp.homepage.body" /> <put-attribute name="footer" value="/tiles/credits.jsp" /> </definition>
The myapp.homepage.body definition will be put inside the myapp.homepage, by putting it inside its body attribute. You will be seeing the definition one inside the other.
You can extend definitions like a Java class. The concepts of abstract definition, extension and override are available.
<definition name="myapp.page.common" template="/layouts/classic.jsp"> <put-attribute name="header" value="/tiles/banner.jsp" /> <put-attribute name="menu" value="/tiles/common_menu.jsp" /> <put-attribute name="footer" value="/tiles/credits.jsp" /> </definition>
<definition name="myapp.homepage" extends="myapp.page.common"> <put-attribute name="title" value="Tiles tutorial homepage" /> <put-attribute name="body" value="myapp.homepage.body" /> </definition>
In this case, the header, menu and footer are inherited from the myapp.page.common definition, while the rest is defined inside the "concrete" definition.
<definition name="myapp.homepage.alternate" extends="myapp.homepage" template="/layouts/alternate.jsp" />
The definition has the same attributes, but its template changed. The result is that the content is the same, but the layout is different.
<definition name="myapp.homepage.customer" extends="myapp.homepage"> <put-attribute name="menu" value="/tiles/common_menu_for_customers.jsp" /> </definition>
In this case, the page will have the same appearance as the myapp.homepage definition, but its menu subpage is different.