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.

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

Only one level being returned for Sitetree


Go to End


5 Posts   1051 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, 5523 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, 5523 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!