Skip to content
Advertisement

How to insert a fragment from another template

Web project in java using thymeleaf.
I want to insert in a file:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div th:fragment="srs-header">
         header
    </div>
</body>
</html>

Here is this fragment:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://thymeleaf.org">
<head>
<!--    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />-->
    <meta charset="UTF-8">
</head>
<body>
    <div th:insert="books-header :: srs-header"></div>
</body>
</html>

As a result, I get the error: “Whitelabel Error Page”.
What am I doing wrong?

Advertisement

Answer

It turned out when I wrote like this:

<div th:insert="books-header.html :: srs-header"></div>
Advertisement