SilverStripe 连续获得第一个孩子
我有多个孩子,我将它们显示在网格中。 4 个孩子排成一排。现在,我想为连续的每个第一个和最后一个子元素提供一个额外的类来指定更多样式。我试过:
<% if FirstInRow %>
<div class="gridContent firstInRow"></div>
<% else %>
<div class="gridContent"></div>
<% end_if %>
这就是功能:
function FirstInRow(){
return ($this->Pos(1) % 4 == 1) ? true : false;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在模板中使用
Modulus
和MultipleOf
控件。http://doc.silverstripe.org/sapphire/en /reference/advanced-templates#modulus-and-multipleof
You have the
Modulus
andMultipleOf
controls available to you in the template.http://doc.silverstripe.org/sapphire/en/reference/advanced-templates#modulus-and-multipleof
当您可以从 0 开始时,模数效果会更好。请尝试这样做:
请注意,我还删除了冗余的 ternay 运算符;如果它使代码对您来说更清晰,您可以将其保留。
Modulus works better when you could starting from 0. Try this instead:
Note that I removed the redunandant ternay operator as well; you can leave that in if it makes the code clearer to you.