Jump to:

23450 Posts in 18899 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Only one level being returned for Sitetree

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: 321 Views
  • NeilB
    Avatar
    Community Member
    5 Posts

    Only one level being returned for Sitetree Link to this post

    Hi,

    When I used the code below I don't get the subpages (second and third level of site) in the returned object. For this reason I can't use staticpublisher.

    $pages = SiteTree::get()->filter('ParentID', 54);

    Running SS 3.1.2 upgraded from 2.4.

    Any ideas!

    Thanks,

    Neil

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Only one level being returned for Sitetree Link to this post

    In your example $pages will only be the pages for the a single level. If you want to get the children of those

    $pages = SiteTree::get()->filter('ParentID', 54);

    foreach($pages as $page) {
    $page->Children(); //
    }

    Of course you may want to make that recursive so children of children are included.

  • NeilB
    Avatar
    Community Member
    5 Posts

    Re: Only one level being returned for Sitetree Link to this post

    Thanks Willr,

    Is there a method that returns every page? Staticpublisher example seem to point to SiteTree::get(); but on my site (c. 2500 pages) when I run it it maxs out CPU for a while and doesn't generate any cached versions of pages. But if I isolate a single branch of the site it runs fine using SiteTree::get()->filter('ParentID', 54); for example. Any tips?

    Cheers,
    Neil

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Only one level being returned for Sitetree Link to this post

    Try staticpublisherqueue (https://github.com/silverstripe-labs/silverstripe-staticpublishqueue) which will generate pages through an event system and perhaps better for larger sites (and going to be more scalable than the default static publisher).

    Do you know what part is causing the delay - the fetch of pages or the actual processing of each page? If it's a fetch, then no nice way apart from querying for the page links in batches. The processing of each page can be batched down a bit so rather than calling RebuildStaticCacheTask and rebuilding all pages at once you can do something like

    sake dev/buildcache "start=0&count=300"
    sake dev/buildcache "start=300&count=300"
    ..

  • NeilB
    Avatar
    Community Member
    5 Posts

    Re: Only one level being returned for Sitetree Link to this post

    Thanks great, thanks a mill for the advice, much appreciated!
    (Funny thing is that when the same site was on version 2.3 the staticpublishing worked fine, must be something to do with switch to ORM.)

    Cheers!

    321 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.