noir2k
noir2k

Reputation: 3

How to Breakable Loop in Play Framework template

I am using playFramework 2.1

I would like to break a for loop in a playFramework template.

This is my Code :

@breakable {
   @for((item, count) <- list.zipWithIndex) {
       <tr>
           <td>@item.id</td>
           <td>...</td>
       </tr>
       @if(count > 5){
           @println("break")
           @break
       }
    }
}

But It doesn't work - it displays nothing html tag. It only works for println play console.

Upvotes: 0

Views: 1101

Answers (1)

msiebert
msiebert

Reputation: 45

I'm not sure how you could create this custom tag (I'm kind of new to Play as well), but in this case, you can add a filter to the for statement:

@for((item, count) <- list.zipWithIndex if count <= 5) {
    <tr>
       <td>@item.id</td>
       <td>...</td>
   </tr>
   @if(count > 5){
       @println("break")
       @break
   }
}

Hope that helps!

Upvotes: 2

Related Questions