I am using apache tiles3 and I have a classic layout with default empty attributes:
<definition name="t-empty" template="/WEB-INF/tiles/template/empty.jsp"/>
//the base template is the site,
<definition name="base" template="/WEB-INF/tiles/layout/classic.jsp">
<put-attribute name="res" value="t-empty"/>
<put-attribute name="header" value="t-empty"/>
<put-attribute name="body" value="t-empty"/>
<put-attribute name="footer" value="t-empty"/>
</definition>
As shon, there is an attribute to be inserted named res
which means the static javascript or css or inline styles.
And for the javascript, I can add them directly in the tile, but for the css or inline styles, they bave to be added inside the head
section, that's why I add the res
placeholder.
Now I have a layout which may use the bootstrape and backbone library, so I define it like this:
<definition name="single-page-bb" extends="base">
<put-attribute name="header" value="/WEB-INF/tiles/template/header.jsp"/>
<put-list-attribute name="res">
<add-attribute value="/WEB-INF/tiles/template/res/jquery.jsp"/>
<add-attribute value="/WEB-INF/tiles/template/res/backbone.jsp"/>
</put-list-attribute>
</definition>
Then for a conrete page, I will put all the required attributes, and its own resources if any:
<definition name="user-list-page" extends="single-page-bb">
<put-attribute name="header" value="/WEB-INF/tiles/fragment/user-list.jsp"/>
<put-list-attribute name="res" inherit="true">
<add-attribute value="/WEB-INF/tiles/fragment/user-list-res.jsp"/>
</put-list-attribute>
</definition>
See the jsps: https://i.stack.imgur.com/qYAdM.png
It works, but I found that this is inconvenient, since I have to put the resources for the user-list
page outside the page.
I wonder if it is possible to put the resources inside the tile user-list
?