en Lopes
en Lopes

Reputation: 2113

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}

Upvotes: 0

Views: 396

Answers (1)

Venu Duggireddy
Venu Duggireddy

Reputation: 806

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

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

Upvotes: 2

Related Questions