动态Thymeleaf包括

时间:2014-05-01 19:10:56

标签: include thymeleaf

是否可以使用像这样的动态Thymeleaf:

<div th:each="module : ${report.modules}" th:include="modules/${module.key} :: ${module.key}"></div>

加载页面时我得到500: 评估SpringEL表达式的异常:“module.key”

1 个答案:

答案 0 :(得分:3)

这是可能的,但您需要稍微重建模板。由于th:includeth:each之前处理,因此需要将divth:include包装为迭代标记。此外,模板的路径必须为String,因此您无法modules/$module.key,因为我认为它不会产生预期的结果。见下面的例子。

<th:block th:each="module : ${report.modules}">
<div th:include="${#strings.concat('modules/', module.key)} :: ${module.key}"></div>
</th:block>
相关问题