我有一个html片段,它包含在布局中。此布局存在于所有页面中。现在我只有一个页面,我想从其中排除这个片段。
布局页面:
<div th:replace="~{chat/head.html :: head}"></div>
<div th:replace="~{chat/footer.html :: footer}"></div>所有页面:包括布局。最后一页:包括版面,但不包括:
<div th:replace="~{chat/footer.html :: footer}"></div>发布于 2019-03-12 10:29:08
一种解决方案是向布局页面添加一个标志:
<div th:replace="~{chat/head.html :: head}"></div>
<th:block th:if="${!#bools.isTrue(hideFooter)}">
<div th:replace="~{chat/footer.html :: footer}"></div>
</th:block>然后在服务器上:
@GetMapping("/thatOnePageThatDoesntNeedAFooter")
public String getThatOnePage(Model model) {
model.addAttribute("hideFooter", true);
return "thatOnePageThatDoesntNeedAFooter";
}逻辑可能看起来有点奇怪,但这将减轻在除这种例外情况外的所有其他情况下向模型添加变量的需求。
请注意,您需要将th:if放在th:replace块之外。如果您将它们放在同一行上,则th:replace将优先于th:if。
https://stackoverflow.com/questions/55099009
复制相似问题