$Pos from bottom inside <% loop DataObjects %>

落花浮王杯 提交于 2019-12-02 02:50:23

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!