如何使用thymeleaf命名空间来包含页面的页眉和页脚而不使用任何templateresolver?

时间:2014-01-11 21:12:28

标签: html5 thymeleaf

我有一个登录页面,其中我已声明包含常用模板,如下所示

“head”是common.html中header属性的片段名称,它包含所有常见的js和css文件。

当我访问URL时,我发现页面上没有加载这些css。在这里需要注意的是,我没有使用任何templateresover类或引擎类,它纯粹是静态的。

任何人都可以帮我吗?

这是login.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:th="http://www.thymeleaf.org">
<head>
<meta name="loginPage" />
<meta th:remove="tag" th:include="../fragments/common :: [//head]"/>

</head>
<body  class="claro">
<div></div>
        <br />
          <div class="grid">
            <div class="col-1-1" style="text-align: center; margin: 0 auto;">
                <form class="form" t">
                    <fieldset>
                        <legend>Please login</legend>
                        <div class="col-1-1">
                            <div class="label">
                                User Name:
                            </div>
                            <div class="input">
                                <input data-dojo-type="dijit/form/TextBox" id="user_name" length="35" required="true" />
                            </div>
                        </div>
                        <div class="col-1-1">
                           <div class="label"> 
                                Password:
                           </div> 
                           <div class="input">
                            <input  id="password" name="password" data-dojo-type="dijit/form/TextBox"
                                type="password" required="required" maxlength="100" />
                           </div>
                         </div>
                           <div class="col-1-1">
                                <div class="module">
                                    <input type="submit" data-dojo-type="dijit.form.Button"
                                        id="save_msg_button" intermediateChanges="false"
                                        label="Login" iconClass="dijitNoIcon"></input>
                                </div>
                           </div>

                    </fieldset>
                </form>
            </div>
         </div>
</body>
</html>

这是common.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head th:fragment="head">
<meta charset="utf-8" />
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>  
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>  
<![endif]-->

<!-- stylesheets -->
<link rel="stylesheet" th:href="@{/css/grid.css}" href=""
    type="text/css" />
<link rel="stylesheet" th:href="@{/css/app.css" href=""
    type="text/css" />
<link rel="stylesheet" th:href="@{/css/app.css" href=""
    type="text/css" />
<link rel="stylesheet" href="../../../cdn/js/dojo/dijit/themes/claro/document.css"
    type="text/css" />
<link rel="stylesheet" href="../../../cdn/js/dojo/dijit/themes/claro/claro.css"
    type="text/css" />
<link rel="stylesheet" href="../../../cdn/js/dojo/dijit/themes/claro/Gridx.css"
    type="text/css" />
<link rel="stylesheet" href="../../../cdn/js/dojo/dijit/themes/claro/Gridx_rtl.css"
    type="text/css" />
<link rel="stylesheet" href="../../../cdn/js/dojo/dijit/themes/claro/ExpandoPane.css"
    type="text/css" />



</head>
<body>
    <div>
        <span>Body goes here</span>
    </div>
</body>
</html>

1 个答案:

答案 0 :(得分:2)

如果我理解正确,您希望使用片段对模板进行静态原型设计。

当Thymeleaf模板用作静态原型时,您将看不到使用th:include / th:replace包含的片段。

在我看来,你有两个选择:

  1. 创建一个静态原型设计代码,该代码将在运行时删除,如此文件中所示:https://github.com/thymeleaf/thymeleafexamples-layouts/blob/master/src/main/webapp/WEB-INF/views/home/homeNotSignedIn.html

  2. 使用百里香 - 一个非官方的JavaScript库,它是Thymeleaf的标准片段包含功能的实现,为th:some或th:replace等一些Thymeleaf属性提供静态支持。请参阅:http://sourceforge.net/u/jjbenson/wiki/thymol/