21287 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 862 Views |
-
[HELP] Need to add a count records??

11 August 2009 at 5:04pm
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 %>
-
Re: [HELP] Need to add a count records??

11 August 2009 at 6:17pm
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 %>
| 862 Views | ||
|
Page:
1
|
Go to Top |


