can one inside a loop in template over a DataObject somehow tell wether you're at $Pos 24 but counted from bottom - something like:
<% 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 %>
In Silverstripe 3, to be able to do:
<% if FromBottom(24) %>
Hello
<% end_if %>
you'll have to add MyCustomIteratorFunctions.php
to your /code folder with the following contents:
<?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);
}
}
as seen here: https://groups.google.com/forum/#!msg/silverstripe-dev/DVBtzkblZqA/PWxanKGKDYIJ
来源:https://stackoverflow.com/questions/14096216/pos-from-bottom-inside-loop-dataobjects