可以在模板中的一个循环中通过DataObject以某种方式告诉你是否在$ Pos 24但从底部开始计算 - 类似于:
<% if Pos = "-24" %>do stuff<% end_if %>
or like
<% if TotalItems - 24 = Pos %>do stuff<% end_if %>
or like
<% if Last(24) %>do stuff<% end_if %>
答案 0 :(得分:4)
在Silverstripe 3中,能够做到:
<% if FromBottom(24) %>
Hello
<% end_if %>
您必须使用以下内容将MyCustomIteratorFunctions.php
添加到/ code文件夹中:
<?php
class MyCustomIteratorFunctions implements TemplateIteratorProvider
{
protected $iteratorPos;
protected $iteratorTotalItems;
public static function get_template_iterator_variables()
{
return array('FromBottom');
}
public function iteratorProperties($pos, $totalItems)
{
$this->iteratorPos = $pos;
$this->iteratorTotalItems = $totalItems;
}
function FromBottom($num)
{
return (($this->iteratorTotalItems - $this->iteratorPos) == $num);
}
}
如此处所示:https://groups.google.com/forum/#!msg/silverstripe-dev/DVBtzkblZqA/PWxanKGKDYIJ