# th:insert与th:replace（与th:include）的区别

`th:insert`与`th:replace` （与`th:include`，从3.0开始不推荐使用）的区别是什么呢？

* `th:insert`是最简单的：它会简单地把指定的片段作为它的宿主标签的主体插入。
* `th:replace`实际上用指定的段落取代它的宿主标签。
* `th:include`类似于`th:insert`，但是不是插入片段，而是仅仅插入片段的内容。

所以，如下的HTML片段：

```markup
<footer th:fragment="copy">
  &copy; 2011 The Good Thymes Virtual Grocery
</footer>
```

像这样，在宿主`<div>`标签里被包含了三次：

```markup
<body>

  ...

  <div th:insert="footer :: copy"></div>

  <div th:replace="footer :: copy"></div>

  <div th:include="footer :: copy"></div>

</body>
```

会生成：

```markup
<body>

  ...

  <div>
    <footer>
      &copy; 2011 The Good Thymes Virtual Grocery
    </footer>
  </div>

  <footer>
    &copy; 2011 The Good Thymes Virtual Grocery
  </footer>

  <div>
    &copy; 2011 The Good Thymes Virtual Grocery
  </div>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jack80342.gitbook.io/thymeleaf/i.-using-thymeleaf/8-mo-ban-she-ji/8.1-bao-han-mo-ban-pian-duan/difference-between-th-insert-and-th-replace-and-th-include.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
