문제

Is it possible to use to do a dynamic Thymeleaf include like this:

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

I get a 500 when loading the page: Exception evaluating SpringEL expression: "module.key"

도움이 되었습니까?

해결책

It is possible but you need to rebuild your template little bit. Because th:include is processed before th:each you need wrap div with th:include to iteration tag. Also path to template must be String so you can't do modules/$module.key as it's not produce desired result I suppose. See example below.

<th:block th:each="module : ${report.modules}">
<div th:include="${#strings.concat('modules/', module.key)} :: ${module.key}"></div>
</th:block>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top