我正在使用Apache Tiles 2.1开发一个项目。
我遇到了一个问题,即使用列表属性扩展模板正在创建这些列表项的重复项......每个继承级别的一组重复项。
例如,这是基本定义,以及它将生成的页面:
<definition name="base" template="somePage.jsp">
<!-- snip -->
<put-list-attribute name="styles">
<add-attribute value="base.css"/>
</put-list-attribute>
</definition>
正如预期的那样,这将产生像这样的html:
<html>
<head>
<!-- snip -->
<link rel="stylesheet" type="text/css" href="../css/base.css"/>
</head>
<body>
<!-- snip-->
</body>
</html>
如果我像这样扩展定义:
<definition name="firstExtension" extends="base">
<!-- snip -->
<put-list-attribute name="styles" inherit="true">
<add-attribute value="someOther.css"/>
</put-list-attribute>
</definition>
同样,正如预期的那样,我得到了这个结果:
<html>
<head>
<!-- snip -->
<link rel="stylesheet" type="text/css" href="../css/base.css"/>
<link rel="stylesheet" type="text/css" href="../css/someOther.css"/>
</head>
<body>
<!-- snip-->
</body>
</html>
但是,如果我扩展前一个,问题就开始了:
<definition name="secondExtension" extends="firstExtension">
<!-- snip -->
<put-list-attribute name="styles" inherit="true">
<add-attribute value="evenMore.css"/>
</put-list-attribute>
</definition>
这个二级扩展产生了这个:
<html>
<head>
<!-- snip -->
<link rel="stylesheet" type="text/css" href="../css/base.css"/>
<link rel="stylesheet" type="text/css" href="../css/base.css"/> <!-- note: duplicate! -->
<link rel="stylesheet" type="text/css" href="../css/someOther.css"/>
<link rel="stylesheet" type="text/css" href="../css/evenMore.css"/>
</head>
<body>
<!-- snip-->
</body>
</html>
“原始”列表的继承属性对于每个扩展定义都会重复一次,即使该定义没有向列表属性添加任何内容。
我试图保持我的定义非常干燥,所以在某些情况下我有 4-5 级继承。因此,“总是使用”的 css 文件会被重复4-5 次,即使只有“最低”的定义是唯一将另一个 css 文件添加到列表中的定义。
这是瓷砖中的错误,还是我只是以非预期的方式使用它们?有什么方法可以解决这个问题,而无需简单地消除inherit="true"
? 如果可能,我想避免在每个定义上编写相同的“核心”css 和 javascript 文件。