include - 动态 Thymeleaf 包括

标签 include thymeleaf

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

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

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

最佳答案

这是可能的,但您需要稍微重建您的模板。因为 th:includeth:each 之前被处理,你需要用 th:include 包装 div 到迭代标签。模板的路径也必须是 String 所以你不能做 modules/$module.key 因为它不会产生我想的预期结果。请参见下面的示例。

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

关于include - 动态 Thymeleaf 包括,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23414779/

相关文章:

c - #include 比它出现在程序中更早

javascript - 如何使用下拉列表中所选对象的属性自动填充文本框

tiles - 让 Tiles 的 put-list-attribute 与 Thymeleaf 模板一起使用

html - 属性文件中带有 Thymeleaf -UTF-8 的 Spring Boot CRUD 应用程序

thymeleaf - 如何在 Thymeleaf 模板中添加不包含在生成的 HTML 中的源代码注释?

JavaScript - include() - 检查数组中是否有多个元素

c++ - 如何指定远程预处理器包含路径,如 192.0.2.17 ://usr/include

include - 创建包含文件时出错 缺少 REPORT/PROGRAM 语句

ios - 如何在混合代码 Objective-C/C++ 文件(.mm 文件)中使用 PHPhotoLibrary?

html - Thymeleaf: th: 在下拉列表中选择