Reputation: 1159
I have a accordion group in my play scala template, the first accordions body needs be in class "in collapse" (eg : class="accordion-body in collapse" ) and other accordions need to have class="accordion-body in collapse". How do I define variables in scala template so that I can set the accordions class appropriately based on if it's a first record / not.
@for(t <- tests) {
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#basic-accordion" href="#[email protected]()">@t.getName()</a>
</div>
<div id="[email protected]()" class="accordion-body in collapse">
<div class="accordion-inner">
<p>@t.getDescription()</p>
<p> The demo will get expired on - @t.getEndDate() </p>
</div>
</div>
</div>
}
Upvotes: 0
Views: 513
Reputation: 4562
You can use @for
loop on scala templates like this :
@for((t, index) <- tests.zipWithIndex) {
@if(index == 0) {
// first index
...
} else {
...
}
}
The index
variable is automatically assigned and and incremented for each loop starting with 0
as the first index.
Upvotes: 2