Search code examples
javaspring-bootthymeleafbackend

Why does my th:each not work in my div? Thymleaf


I'm trying to th:text in my div but it doesnt seem to work

I tried doing it with a table and i get the data i need but when i put it in a div it doesnt work

     <div class="info"  data-th-each="shoes: ${shoesList}">
          <p th:text="$(shoes.name)"></p>
          <p th:text="$(shoes.description)"></p>
          <p th:text="$(shoes.price)"></p>          
      </div>

This works tho

<table>

      <tr data-th-each="shoes : ${shoesList}">    
        <td th:text="${shoes.name}"></td>
        <td th:text="${shoes.description}"></td>
        <td th:text="${shoes.price}"></td>
      </tr>        
  
</table>

Solution

  • I think, it will be following way ( correct $(shoes.name) to ${shoes.name} )

    <div class="info"  th:each="shoes : ${shoesList}">
          <p th:text="${shoes.name}"></p>
          <p th:text="${shoes.description}"></p>
          <p th:text="${shoes.price}"></p>          
      </div>
    

    Please visit this link Iteration thymeleaf