【发布时间】:2014-08-25 19:56:47
【问题描述】:
使用"template decoration instead of inclusion" technique时如何检查Thymeleaf片段是否定义?
在下面的 template.html 示例中,我只希望在定义片段时呈现脚本标记
<html th:fragment="page" xmlns:th="...">
...
<div class="container" th:include="this :: content"></div>
<script th:include="this :: script"></script>
...
</html>
但是在我的 index.html 中,它使用了上面的模板,没有定义脚本片段,但脚本标签仍然会呈现
<html th:include="template :: page">
...
<div th:fragment="content">
...
</div>
</html>
我试过th:if="#{this :: script}",但没有成功
【问题讨论】:
-
你试过
th:replace而不是th:include吗?