> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/thymeleaf/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](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).

# 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>
```
