Jump to:

22972 Posts in 11596 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » [HELP] Need to add a count records??

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 956 Views
  • b0bro
    Avatar
    Community Member
    38 Posts

    [HELP] Need to add a count records?? Link to this post

    How do i put an if statment on every third record??

    eg every third record i need to print some extra code like <br /> for example

    Do I add a counter to the php(below)
    -------------------
    function LatestExhibitions(){
    return DataObject::get("ExhibitionPage", "ParentID = $this->ID", "`ExhibitionPage`.ID DESC", "", 9);
    }
    ------------------

    or to the control

    <% control LatestExhibitions %>

    <% end_control %>

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: [HELP] Need to add a count records?? Link to this post

    A DataObject within a DataObjectSet has access to it's current iterator position through Pos().

    Therefore, in ExhibitionPage add the following method:

    function MultipleOf($mod, $offset = 1) {
       return ((($this->Pos() + $offset) % $mod) == 0);
    }

    Then, in your template, you can do (for example):

    <% control LatestExhibitions %>
       <h3>Title.XML</h3>
       <% if MultipleOf(3) %>
          <br />
       <% end_if %>
    <% end_control %>

    956 Views
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.