I am migrating a project from JSP to Thymeleaf.
In some JSPs I did fancy stuff like this:
<script type="text/javascript">
//<c:forEach items="${pages}" var="page">
...
var l = new google.maps.LatLng("${page.lat}", "${page.long}");
...
//</c:forEach>
</script>
How could I do the same with Thymeleaf?
This is the working solution with Thymeleaf 3.0.2:
<script th:inline="javascript">
/*<![CDATA[*/
/*[# th:each="page : ${pages}"]*/
...
var l = new google.maps.LatLng(/*[[${page.lat}]]*/, /*[[${page.long}]]*/);
...
/*[/]*/
/*]]>*/
</script>
Why and how it works is explained here: [MAJOR FEAT] New syntax for textual template modes #395
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With