htmlthymeleaf

Thymeleaf: literals and variables in a HTML id


I have this piece of code in Thymeleaf:

<tr th:each="image: ${images}" >

   <img id="|'idAwesomeIcon${image.id}'|" .. />

</tr>

also I tried

<tr th:each="image: ${images}" >

   <img id=“idAwesomeIcon|${image.id}|" .. />

</tr>

also I tried

<tr th:each="image: ${images}" >

   <img id="\'idAwesomeIcon' + ${image.id} +'\'" .. />

</tr>

expecting the id to be replace with something like idAwesomeIcon666 but when I see the source code of the HTML page there is no such a substitution and I can still see ${image.id}


Solution

  • You have to use th:id attribute if you want to dynamically populate values

    <img th:id="'idAwesomeIcon'+${image.id}" .. />