简体   繁体   English

org.thymeleaf.exceptions.TemplateInputException:解决片段错误:无法解析模板或片段

[英]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.

相关问题 Thymeleaf:org.thymeleaf.exceptions.TemplateInputException - Thymeleaf : org.thymeleaf.exceptions.TemplateInputException 如何调试org.thymeleaf.exceptions.TemplateInputException? - How to debug org.thymeleaf.exceptions.TemplateInputException? org.thymeleaf.exceptions.TemplateInputException:Spring Boot - org.thymeleaf.exceptions.TemplateInputException: Spring Boot org.thymeleaf.exceptions.TemplateInputException:异常分析文档:template =“ login”,第36行-第3列 - org.thymeleaf.exceptions.TemplateInputException: Exception parsing document: template=“login”, line 36 - column 3 我的spring-boot应用程序给出以下错误“ org.thymeleaf.exceptions.TemplateInputException:” - My spring-boot app gives the following error “org.thymeleaf.exceptions.TemplateInputException:” springboot项目的问题:org.thymeleaf.exceptions.TemplateInputException - issue with springboot project : org.thymeleaf.exceptions.TemplateInputException Thyemleaf 嵌套迭代触发器 org.thymeleaf.exceptions.TemplateInputException - Thyemleaf nested iteration triggers org.thymeleaf.exceptions.TemplateInputException 替换片段时解析 thymeleaf 模板时出错 - Error resolving thymeleaf template when replacing fragment 如何摆脱 org.thymeleaf.exceptions.TemplateInputException: 同时使用 thymeleaf 表达式以引导卡的形式打印数据? - how to get rid of org.thymeleaf.exceptions.TemplateInputException: while using thymeleaf expression to print data in form of bootstrap cards? Thymeleaf 引发异常 (TemplateInputException) 并显示消息“解析模板 [书籍/列表] 时出错:...” - Thymeleaf throws exception (TemplateInputException) with message “Error resolving template [books/list]:…”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM