Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

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

[HELP] Need to add a count records??

Go to End

2 Posts   1314 Views


Community Member, 38 Posts

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


Community Member, 712 Posts

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 %>
	<% if MultipleOf(3) %>
		<br />
	<% end_if %>
<% end_control %>