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 %>
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 %>
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