Jump to:

3444 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » Passing Variables from Template to Class?

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1461 Views
  • Garrett
    Community Member
    245 Posts

    Passing Variables from Template to Class? Link to this post

    I'm iterating in my template through a DataObjectSet coming from a custom DB::query(). I need to start a new html list every 25 items. The trouble is, I don't know how to pass the loop position ($Pos) back to the PHP class to do the modulo calculation. The trouble is, I don't know where to put my code.


    <% control GetPastClients %>
       <% if BeginNewList(25) %>
          <div style="float:left;">
       <% end_if %>
       <% if EndList %>
       <% end_if %>
    <% end_control %>


    function BeginNewList($ItemsPerList) {
       if(($this->Pos()-1) % $ItemsPerList == 0) {
          return true;
       } else {
          return false;

    There are 159 items in the DataObjectSet. Can anyone tell me why this function prints out nothing? It's as if it doesn't exist. What I erally need to do here is to pass the Pos() from the template [<% if BeginNewList(Pos) %>] but I I can't seem to do this for some reason. Anyoen have any idea how I can accomplish what I'm trying to do here?


  • baba-papa
    Community Member
    279 Posts

    Re: Passing Variables from Template to Class? Link to this post

    There is an excellent ducumentation on how to implement pagination:

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.