Piotr
Piotr

Reputation: 4963

How do I extend templates in tiles?

I have one master template that has the general site layout frame: "/WEB-INF/jsp/common.jsp" Then I have another template that will be generally used for another number of pages with similar layout: "/WEB-INF/jsp/features/common.jsp"

The features template basically defines the content of attribute "content" of the "master" template.

I have tried to solve this the following way:

<definition name="product.common" template="/WEB-INF/jsp/common.jsp">
    <put-attribute name="content" value="/WEB-INF/jsp/features/common.jsp" />
</definition>
<definition name="features/index" extends="product.common">
    <put-attribute name="title" value="Features" />
    <put-attribute name="rightContent" value="/WEB-INF/jsp/features/index.jsp" />
</definition>

But this does not work. I get the following error message in my stack trace:

org.apache.tiles.template.NoSuchAttributeException: Attribute 'rightContent' not found.

But the features-template does have the following:

<tiles:insertAttribute name="rightContent" />

Any ideas?

Upvotes: 1

Views: 5038

Answers (1)

Raghuram
Raghuram

Reputation: 52655

I guess what you need is nesting definitions. You could try something like this.

<definition name="features.common" template="/WEB-INF/jsp/features/common.jsp">
</definition>

<definition name="product.common" template="/WEB-INF/jsp/common.jsp">
    <put-attribute name="content" value="features.common" />
</definition>

<definition name="features/index" extends="product.common">
    <put-attribute name="title" value="Features" />
    <put-attribute name="rightContent" value="/WEB-INF/jsp/features/index.jsp" />
</definition>

Upvotes: 1

Related Questions