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

Pagination of Children?


Go to End
Reply


4 Posts   866 Views

Avatar
ambient

Community Member, 128 Posts

20 December 2013 at 5:51am

Howdy!

I'm trying to get pagination to work in the following situation. I am not nor do I want to use dataobjects.

So I have a StoryHolder Page that has 10 subpages (children). The subpages PageType is StoryPage.

The StoryHolder page has no submenu. The StoryPages are displayed in the main content area by $StoryTitle and $Content.Summary using

<% if Children %>
    <% control Children %>
    <div class="story">
      <h3>$StoryTitle</h3>
      $Content.Summary
    </div>
    <% end_control %>
<% end_if %>

But what I want to do is only have 3 stories display on the holder page with pagination for the other pages.

I've tried
StoryHolder.ss

<% if Children %>
    <% control Children.Pagination %>
    <div class="story">
      <h3>$StoryTitle</h3>
      $Content.Summary
    </div>
    <% end_control %>
    <% end_if %>

    <% if Story.MoreThanOnePage %>
    <div class="pagination" style="float:right;">
      <p>
        <% if Story.NotFirstPage %>
        <a class="prev" href="$Story.PrevLink" title="View the previous page">&lt; Prev</a>
        <% end_if %>
        <span>
        <% control Story.PaginationSummary(0) %>
        <% if CurrentBool %>
        <span class="current">$PageNum</span>
        <% else %>
        <% if Link %>
        <a href="$Link" class="numbers" title="View page number $PageNum">$PageNum</a>
        <% else %>
        &hellip;
        <% end_if %>
        <% end_if %>
        <% end_control %>
        </span>
        <% if Story.NotLastPage %>
        <a class="next" href="$Story.NextLink" title="View the next page">Next &gt;</a>
        <% end_if %>
      </p>
    </div>
<% end_if %>

With
StoryHolder.php

function Story() {
		if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) 
		{
			$_GET['start'] = 0;
		}
	
		$SQL_start = (int)$_GET['start'];
	
		$newsEntries = DataObject::get('StoryPage', '', 'Title DESC');
		$doSet = new DataObjectSet();
		foreach ($newsEntries as $newsEntry) {
			if ($newsEntry->canView()) {
				$doSet->push($newsEntry);
			}
    }
    $doSet->setPageLimits($SQL_start, 5, $doSet->Count());
    return $doSet;

I'm sure it's a little sloppy, I'm not the best coder and have been going through a lot of trial and error.
Anyway what it does now is show the pagination but instead of displaying only 3 on each &start=3 it shows all of them.
Something to do with the control Children maybe?

I've searched quite a bit for a solution but mostly all I can find is pagination for dataobjects which I don't want to use in this case.

Any help is appreciated :)

Avatar
ambient

Community Member, 128 Posts

7 January 2014 at 1:50am

Does anybody have any ideas on this at all?
Thanks

Avatar
Willr

Forum Moderator, 5521 Posts

7 January 2014 at 4:35pm

Pagination for dataobjects as you've seen will still work for pages. Have a read of the documentation online for more reference - http://doc.silverstripe.org/framework/en/howto/pagination

In your case if you want to paginate the children then create a new function on your StoryHolder

public function PaginatedChildren() {
return new PaginatedList($this->Children(), $this->request);
}

Then you can use PaginateChildren as your paginated list. More documentation on that doc page.

Avatar
ambient

Community Member, 128 Posts

28 January 2014 at 4:34am

Hey Willr, apologies for the late reply to your post.
I should have mentioned at the start that I'm using SS 2.4.
Anyway I appreciate your help!
Cheers