【发布时间】:2015-05-12 10:25:24
【问题描述】:
如何在使用 Tiles2 作为模板引擎的同时有效地使用 ThymeLeaf 自然模板。我有一个简单的瓷砖定义:
<tiles-definitions>
<definition name="/**;layout:*" template="templates/{2}_layout">
<put-attribute name="header" value="templates/header"/>
<put-attribute name="content" value="/{1}"/>
<put-attribute name="footer" value="templates/footer"/>
</definition>
...
</tiles-definitions>
和我的布局
<html lang="pl" xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.springframework.org/security/tags"
xmlns:tiles="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" th:href="@{~/css/bootstrap.min.css}" href="../../../css/bootstrap.min.css"/>
... and many others
</head>
<body>
<div class="top-header" tiles:include="header">Header to include</div>
<div class="container-main" tiles:include="content">Content to include</div>
<div tiles:include="footer">Footer to include</div>
</body>
还有一个简单的 content.html 模板
<div id="main" class="panel panel-main">
<div id="contents" class="panel-body">
bla bla bla
</div>
</div>
我遇到的问题是:
如果我尝试在本地检查 content.html,那么它看起来不像应该的那样,因为我没有定义 <html> 和 <head> 具有 CSS 和 JS 定义。
如果我添加了<html><head> 标签,那么在运行时我在结果页面上有许多 html 定义(来自页眉/内容/页脚模板)!
对我来说一个完美的解决方案可能是:我想使用 <html><head> 标记定义 content.html 以充分利用自然模板和语法检查,然后以某种方式包含此文件但不包含这些标记(只有 body 或 div ) 是否可以?
【问题讨论】:
-
将 thymeleaf 与 thymeleaf 布局方言一起使用。更清洁的方法..
-
我发现了这个:blog.codeleak.pl/2013/11/…。它看起来是一个非常好的、简单而优雅的解决方案。
-
@MarekRaszewski 你会不会有同样的问题,或者你会离开 Tiles2 吗?
-
我已经离开 Tiles2 并使用上面链接中的解决方案将我的项目移动到干净的 ThymeLeaf 中。目前我对它没有任何问题,它看起来很有前途。
标签: java spring-mvc thymeleaf apache-tiles tiles2