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, biapar, Willr, Ingo, swaiba, simon_w

Only one level being returned for Sitetree


Reply


5 Posts   413 Views

Avatar
NeilB

Community Member, 5 Posts

9 December 2013 at 11:58pm

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

Avatar
Willr

Forum Moderator, 5513 Posts

11 December 2013 at 8:32pm

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.

Avatar
NeilB

Community Member, 5 Posts

11 December 2013 at 10:38pm

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

Avatar
Willr

Forum Moderator, 5513 Posts

11 December 2013 at 10:46pm

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

Avatar
NeilB

Community Member, 5 Posts

11 December 2013 at 11:11pm

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!