> 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.2-parameterizable-fragment-signatures.md).

# 8.2 参数化片段签名

为了给模版片段，创建一种更类似于函数的机制，用`th:fragment`定义的片段可以指定一系列参数：

```markup
<div th:fragment="frag (onevar,twovar)">
    <p th:text="${onevar} + ' - ' + ${twovar}">...</p>
</div>
```

这需要使用以下两种语法，从`th:insert`或者`th:replace`调用片段：

```markup
<div th:replace="::frag (${value1},${value2})">...</div>
<div th:replace="::frag (onevar=${value1},twovar=${value2})">...</div>
```

注意：在最后那个选项里，顺序并不重要：

```markup
<div th:replace="::frag (twovar=${value2},onevar=${value1})">...</div>
```
