Iterating a section of HTML

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Iterating a section of HTML

srivaradhan
Hi,

I want to repeat the following 10 lines for every item in a list.

<h2 class="class1">
   <a href="#">One</a>
</h2>
			
<div class="class2">
  <div class="class3">
	<h4>Sub 1</h4>
   </div>
</div>

All the th:each examples that I have seen works only with one html element at a time. How do I repeat for
a group of statements like above?. In the JSP/Freemarker world, I put the for loop outside these 10 lines.

Please help.

-Best Regards.
Sri.
Reply | Threaded
Open this post in threaded view
|

Re: Iterating a section of HTML

Emanuel
Administrator
One solution is similar to the Freemarker example you brought up, which is to put the loop outside those 10 lines.  Since the loop has to go in an element, you can add a th:remove="tag" to that element so it will be removed after the loop has been processed:

<div th:each="..." th:remove="tag">

  <h2 class="class1">
    <a href="#">One</a>
  </h2>
			
  <div class="class2">
    <div class="class3">
      <h4>Sub 1</h4>
    </div>
  </div>

</div>
Reply | Threaded
Open this post in threaded view
|

Re: Iterating a section of HTML

srivaradhan
Thanks Emanuel.  That works like charm!.

Also, learned about the new th:remove from you.

-Sri