[英]org.thymeleaf.exceptions.TemplateInputException: Error resolving fragment: template or fragment could not be resolved
I have a weird issue where some of my html files are not being included when I use replace or include. 我有一个奇怪的问题,当我使用替换或包含时,某些HTML文件未包含在内。 What would cause this?
是什么原因造成的?
header.html 了header.html
<header id="header" xmlns:th="http://www.thymeleaf.org">
<div th:replace="/blocks/topbar :: topbar"></div>
</header>
topbar.html topbar.html
<div class="top-bar">
<div class="container">
<div class="row">
<div class="col-sm-6 col-xs-4">
<div class="top-number"><p><i class="fa fa-phone-square"></i> +0123 456 70 90</p></div>
</div>
<div class="col-sm-6 col-xs-8">
<div class="social">
<ul class="social-share">
<li><a href="#"><i class="fa fa-facebook"></i></a></li>
</ul>
</div>
</div>
</div>
</div><!--/.container-->
</div><!--/.top-bar-->
Error: 错误:
org.thymeleaf.exceptions.TemplateInputException: Error resolving fragment: "~{'/blocks/topbar' :: topbar}": template or fragment could not be resolved (template: "blocks/header" - line 3, col 10)
There is no th:fragment="topbar"
in your topbar.html
. 您的
topbar.html
没有th:fragment="topbar"
topbar.html
。 An additional <div>
may solve your problem. 附加的
<div>
可能会解决您的问题。
<div th:fragment="topbar"> <!--fragment div start--> <div class="top-bar"> <div class="container"> <div class="row"> <div class="col-sm-6 col-xs-4"> <div class="top-number"> <p><i class="fa fa-phone-square"></i> +0123 456 70 90</p> </div> </div> <div class="col-sm-6 col-xs-8"> <div class="social"> <ul class="social-share"> <li><a href="#"><i class="fa fa-facebook"></i></a> </li> </ul> </div> </div> </div> </div> <!--/.container--> </div> <!--/.top-bar--> </div> <!--fragment div end-->
You don't always need a th:fragment, you could have used ".top-bar" instead of "topbar": 您并不总是需要th:fragment,可以使用“ .top-bar”代替“ topbar”:
<div th:replace="/blocks/topbar :: .top-bar"></div>
Class selectors are totally valid and you have a ton more selector possibilities in thymeleaf, see here: http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#appendix-c-markup-selector-syntax 类选择器完全有效,在百里香中有更多的选择器可能性,请参见此处: http : //www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#appendix-c-markup-selector-syntax
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.