8.2 参数化片段签名

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

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

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

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

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

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