Jump to:

23478 Posts in 18941 Topics by 2878 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: 1001 Views
  • b0bro
    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
    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 %>
       <% if MultipleOf(3) %>
          <br />
       <% end_if %>
    <% end_control %>

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.