Reputation: 3016
I have a weird issue where some of my html files are not being included when I use replace or include. What would cause this?
header.html
<header id="header" xmlns:th="http://www.thymeleaf.org">
<div th:replace="/blocks/topbar :: topbar"></div>
</header>
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)
Upvotes: 5
Views: 12636
Reputation: 2521
You don't always need a th:fragment, you could have used ".top-bar" instead of "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
Upvotes: 2
Reputation: 496
There is no th:fragment="topbar"
in your topbar.html
.
An additional <div>
may solve your problem.
<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-->
Upvotes: 12