Create a table in thimeleaf

I am new to thimelia and trying to make a simple table using an array and every loop.

My code looks like this:

<!DOCTYPE HTML> <html xmlns:th="http://www.thymeleaf.org"> <head> <title>Smoke Tests</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> </head> <body> <table border="1" style="width:300px"> <tr> <td>Test Name</td> </tr> <tr th:each="smokeTest : ${smokeTests}"> <td> th:text="${smokeTest.name}">A Smoke Test' </td> </tr> </table> </body> </html> 

Basically my problem is that I cannot start the loop as the <td> limits of <tr> s. Is there a way for this code to work?

+12
html html-table each thymeleaf
source share
3 answers

A simple solution that comes to mind first:

 <th:block th:each="smokeTest : ${smokeTests}"> <tr> <td th:text="${smokeTest.name}">A Smoke Test'</td> </tr> </th:block> 

Details: http://www.thymeleaf.org/whatsnew21.html#bloc

+6
source share

You have to put th: text as an attribute of the tag, therefore

 <tr th:each="smokeTest : ${smokeTests}"> <td th:text="${smokeTest.name}">A Smoke Test'</td> </tr> 

must work.

+10
source share

Although it’s too late to answer. It works more specifically as

 <tr th:each="smokeTest : ${smokeTests}"> <td><p th:text="${smokeTest.name}"></p></td> </tr> 
0
source share

All Articles