$Pos from bottom inside <% loop DataObjects %>

后端 未结 1 955
北恋
北恋 2021-01-24 05:07

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


        
1条回答
  •  隐瞒了意图╮
    2021-01-24 05:21

    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:

    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

    0 讨论(0)
提交回复
热议问题