Jump to:

23493 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Pagination of Children?

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: 367 Views
  • ambient
    Avatar
    Community Member
    123 Posts

    Pagination of Children? Link to this post

    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

  • ambient
    Avatar
    Community Member
    123 Posts

    Re: Pagination of Children? Link to this post

    Does anybody have any ideas on this at all?
    Thanks

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Pagination of Children? Link to this post

    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.

  • ambient
    Avatar
    Community Member
    123 Posts

    Re: Pagination of Children? Link to this post

    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

    367 Views
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.