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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

Passing Variables from Template to Class?


Go to End


2 Posts   2108 Views

Avatar
Garrett

Community Member, 245 Posts

4 March 2010 at 4:28am

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.

Template:

<% control GetPastClients %>
	<% if BeginNewList(25) %>
		<div style="float:left;">
		<ul>
	<% end_if %>
			<li>
				<h6>$ClientName</h6>
			</li>
	<% if EndList %>
		</ul>
		</div>
	<% end_if %>
<% end_control %>

PHP:

function BeginNewList($ItemsPerList) {
	if(($this->Pos()-1) % $ItemsPerList == 0) {
                echo("HELLO!");
		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?

Thanks,
Garrett

Avatar
baba-papa

Community Member, 279 Posts

7 March 2010 at 5:09am

There is an excellent ducumentation on how to implement pagination:
http://doc.silverstripe.org/doku.php?id=private:recipes:pagination