我想创建单独的css文件并希望使用它,而不是再次复制css文件.
使用这种方法,我可以通过调用它来重用cssfilecommon.html,如果我想要一些其他的CSS需要我可以在单独的页面中添加它并只调用该页面
<tiles:insertAttribute name="cssfilecommon" /> - common css file
<tiles:insertAttribute name="pagespecific" /> - some other css file
Run Code Online (Sandbox Code Playgroud)
-
我们可以这样做,如果有人试过,请告诉我.
布局文件
<!DOCTYPE html>
<html xmlns:tiles="http://www.thymeleaf.org">
<head>
**<tiles:insertAttribute name="cssfile" />**
</head>
<body>
<div tiles:include="header">Header Block</div>
<div tiles:substituteby="body">Body Block</div>
<div tiles:substituteby="footer">Footer Block</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
titles-def.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://struts.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="home" template="basiclayout/layout" >
<put-attribute name="cssfilecommon" value="bout/cssfilecommon"/>
<put-attribute name="header" value="bout/header"/>
<put-attribute name="menu" value="bout/Menu"/>
<put-attribute name="footer" value="bout/footer"/>
</definition>
Run Code Online (Sandbox Code Playgroud)
- cssfilecommon.html
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link href="css/jquery-ui-1.10.3.custom.css" th:href="@{css/jquery-ui-1.10.3.custom.css}" rel="stylesheet" type="text/css" />
<link href="css/ui.jqgrid.css" th:href="@{css/ui.jsd.css}" rel="stylesheet" type="text/css"/>
Run Code Online (Sandbox Code Playgroud)
是的,使用普通瓷砖,您可以这样做:
布局文件:
<head>
<tiles:insertAttribute name="cssfilecommon" />
<tiles:insertAttribute name="pagespecific" ignore="true" />
</head>
Run Code Online (Sandbox Code Playgroud)
titles-def.xml文件:
<definition name="home" template="basiclayout/layout" >
<put-attribute name="cssfilecommon" value="bout/cssfilecommon"/>
<put-attribute name="pagespecific" value="bout/pagespecific"/>
...
</definition>
Run Code Online (Sandbox Code Playgroud)
ignore注意属性的用法:
如果该属性设置为 true,并且名称指定的属性不存在,则只需返回而不写入任何内容。默认值为 false,这将导致抛出运行时异常。
但是,据我所知,您正在使用 Thymeleaf,它可能还不支持它:#17
| 归档时间: |
|
| 查看次数: |
1389 次 |
| 最近记录: |