gpt4 book ai didi

Silverstripe 检查是否在循环中的第一次迭代

转载 作者:行者123 更新时间:2023-12-04 05:10:52 24 4
gpt4 key购买 nike

如何检查循环是否处于第一次迭代?

我想将一个类添加到列表项,但只添加到第一个列表,而不是所有列表。

<% loop $LatestNews(3) %>
<% if $this->iteratorPos == 0 %>
<li class="left-arrow highlight">$Title</li>
<% else %>
<li>$Title</li>
<% end_if %>
<% end_loop %>

有办法实现吗?我不想通过 javascript 执行此操作。

最佳答案

是的,有。

请参阅有关模板的 SilverStripe 文档,第 Position Indicators 部分

<% loop $SomeList %>
<% if $First %>
this is the first item<br>
<% else_if $Last %>
this is the last item<br>
<% else %>
this is item number $Pos<br>
<% end_if %>
<% end_loop %>

关于Silverstripe 检查是否在循环中的第一次迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21653257/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com