[英]Spring MVC, Tiles2, ThymeLeaf and Natural Templating
How to effectively use ThymeLeaf natural templating while using Tiles2 as a template engine. 在将Tiles2用作模板引擎时,如何有效地使用ThymeLeaf自然模板。 I have a simple tiles definition:
我有一个简单的图块定义:
<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>
and my layout 和我的布局
<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>
and a simple content.html template 和一个简单的content.html模板
<div id="main" class="panel panel-main">
<div id="contents" class="panel-body">
bla bla bla
</div>
</div>
The problem I have is that: If I tried to check the content.html locally then it would not look like it should because I had not defined <html>
and <head>
having CSS and JS definitions. 我遇到的问题是:如果我尝试在本地检查content.html,那么它将看起来不应该,因为我没有定义具有CSS和JS定义的
<html>
和<head>
。
If I added <html><head>
tags then on runtime I had many html definitions (from header/content/footer templates) on the resulting page! 如果我添加了
<html><head>
标记,那么在运行时,结果页面上会有许多html定义(来自页眉/内容/页脚模板)!
A perfect solution for me could be that: I would like to define content.html with <html><head>
tags taking full advantage of natural templating and syntax checking, and then somehow include this file but without these tags (only body or div) Is it possible? 对我来说,一个完美的解决方案是:我想利用
<html><head>
标签定义content.html,充分利用自然模板和语法检查的优势,然后以某种方式包括此文件,但不包含这些标签(仅body或div ) 可能吗?
You can use 您可以使用
<!-- /* -->
and 和
<!--*/-->.
Every tags inside these comments tags are ignore during runtime (They won't show up in the actual page). 这些注释标签中的每个标签在运行时都会被忽略(它们不会显示在实际页面中)。
<!--/*-->
<html>
<head>
<title>Test</title>
</head>
<body>
<!--*/-->
<div>...</div>
<!--/*-->
<body>
</html>
<!--*/-->
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.