Why Thymeleaf th:insert deletes contents up to first tag

Viewed 62

It is the file with fragments:

<th:block th:fragment="head">
    <title>Title</title>
</th:block>

This is the web page template (not a real example, I do not need to put raw text into the head, but I may need it elsewhere):

<html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head th:insert="fragments/common :: head">
        HA
        <div>HB</div>
        HC
    </head>
</html>

This is the resulting web page:

<html lang="en">
    <head>
    <title>Title</title>
<div>HB</div>
        HC
    </head>

So HA is gone, HB and HC rest. th:include has the same effect, th:replace additionally deletes <head>, </head> rests. Is there a method of just inserting contents from the template, which means not deleting anything from the original? And what is the substantiation behind deleting everything up to the first tag? There is this possibility:

<head>
    <div th:replace="fragments/common :: head" th:remove="tag"></div>
    HA
    <div>HB</div>
    HC3
</head>

which does what I want, but is not it against the philosophy of Thymeleaf which, as far as I know, wants the template to be also a valid HTML document?

0 Answers
Related