Reputation: 822
I have got multiple children which I display in a grid. 4 children fits in a row. Now I want to give every first and last children in a row an extra class to specify more styles. I tried:
<% if FirstInRow %>
<div class="gridContent firstInRow"></div>
<% else %>
<div class="gridContent"></div>
<% end_if %>
That's the function:
function FirstInRow(){
return ($this->Pos(1) % 4 == 1) ? true : false;
}
Upvotes: 0
Views: 972
Reputation: 734
Modulus works better when you could starting from 0. Try this instead:
function FirstInRow(){
return ($this->Pos(0) % 4 == 0);
}
Note that I removed the redunandant ternay operator as well; you can leave that in if it makes the code clearer to you.
Upvotes: 0
Reputation: 381
You have the Modulus
and MultipleOf
controls available to you in the template.
$Modulus(value, offset) // returns an int
$MultipleOf(factor, offset) // returns a boolean.
http://doc.silverstripe.org/sapphire/en/reference/advanced-templates#modulus-and-multipleof
Upvotes: 3