gpt4 book ai didi

thymeleaf - 使用 Thymeleaf 模板而不包含片段定义元素?

转载 作者:行者123 更新时间:2023-12-03 11:03:59 25 4
gpt4 key购买 nike

假设我有两个 Thymeleaf 模板:

index.html :

<!DOCTYPE html>
<html>
<head></head>
<body>
<header>foo</header>
<section>
<div th:replace="fragments/main :: content"></div>
</section>
<footer>bar</footer>
</body>
</html>

片段/main.html :

<!DOCTYPE html>
<html>
<head></head>
<body>
<div th:fragment="content">
<p>This is the main content.</p>
</div>
</body>
</html>

如何防止 Tymeleaf 包含 div定义合成输出中的片段?也就是说,我如何让 Thymleaf 生成以下输出:

<!DOCTYPE html>
<html>
<head></head>
<body>
<header>foo</header>
<section>
<p>This is the main content.</p>
</section>
<footer>bar</footer>
</body>
</html>

代替:

<!DOCTYPE html>
<html>
<head></head>
<body>
<header>foo</header>
<section>
<div>
<p>This is the main content.</p>
</div>
</section>
<footer>bar</footer>
</body>
</html>

最佳答案

使用 th:remove="tag" . ( documentation )

片段/main.html:

<!DOCTYPE html>
<html>
<head></head>
<body>
<div th:fragment="content" th:remove="tag">
<p>This is the main content.</p>
</div>
</body>
</html>

关于thymeleaf - 使用 Thymeleaf 模板而不包含片段定义元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22023890/

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