8.2 参数化片段签名
为了给模版片段,创建一种更类似于函数的机制,用th:fragment
定义的片段可以指定一系列参数:
<div th:fragment="frag (onevar,twovar)">
<p th:text="${onevar} + ' - ' + ${twovar}">...</p>
</div>
这需要使用以下两种语法,从th:insert
或者th:replace
调用片段:
<div th:replace="::frag (${value1},${value2})">...</div>
<div th:replace="::frag (onevar=${value1},twovar=${value2})">...</div>
注意:在最后那个选项里,顺序并不重要:
<div th:replace="::frag (twovar=${value2},onevar=${value1})">...</div>