gpt4 book ai didi

html - 如何在不使用任何模板解析器的情况下使用 thymeleaf 命名空间来包含页面的页眉和页脚?

转载 作者:行者123 更新时间:2023-11-28 00:01:33 25 4
gpt4 key购买 nike

我有一个登录页面,我在其中声明包含如下通用模板

“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>

最佳答案

如果我没理解错的话,您希望使用片段对模板进行静态原型(prototype)设计。

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

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

  1. 创建一个静态原型(prototype)代码,它将在运行时被删除,就像在这个文件中一样:https://github.com/thymeleaf/thymeleafexamples-layouts/blob/master/src/main/webapp/WEB-INF/views/home/homeNotSignedIn.html

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

关于html - 如何在不使用任何模板解析器的情况下使用 thymeleaf 命名空间来包含页面的页眉和页脚?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21067929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com