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.

Customising the CMS /

liveChildren() vs. stageChildren()


Reply


5 Posts   1204 Views

Avatar
Ben Gribaudo

Community Member, 181 Posts

14 April 2009 at 11:31pm

Hello,

I'm working on some code that needs to display all children of a given page (including those hidden from menus). Hierarchy's method stageChildren(true) returns all unpublished children when the site is in dev mode (expected) and all live (published) children when the site is in live mode (unexpected). I would have thought that a call to liveChildren(true) would have been required to fetch the published children.

When should liveChildren() be used instead of stageChildren()?

Thanks,
Ben

Avatar
Ingo

Forum Moderator, 801 Posts

26 April 2009 at 9:52pm

Hm, I don't think there's a distinction per environment in our code - perhaps you're logged in as an admin on the dev environment, but not on the live one? We have SiteTree->canView() which could influence the behaviour, but its not called on lowlevel API methods like stageChildren()

Avatar
Ben Gribaudo

Community Member, 181 Posts

28 April 2009 at 1:09am

Thanks for this info, Ingo. If there is no distinction between environments, does this documentation (below) need updating?
"Return children from the stage site"
http://api.silverstripe.org/sapphire/model/Hierarchy.html#stageChildren

"Return children from the live site, if it exists."
http://api.silverstripe.org/sapphire/model/Hierarchy.html#liveChildren

Avatar
Ingo

Forum Moderator, 801 Posts

28 April 2009 at 8:31am

"Stage" and "Live" are referring to the Versioned extension (you "publish" a page from "stage" to "live"), as opposed to environment types :)

Avatar
Ben Gribaudo

Community Member, 181 Posts

30 April 2009 at 7:12am

Uhhh...I have been using the word "environment" when I mean "live/stage".

With that correct made...a restatement of my original post:

Hierarchy has liveChildren() and stageChildren() methods. The method Children() (think <% Children %> in template code) gets its data by calling stageChildren() even when the site is "live". I would have thought that it would use liveChildren() when the site is "live".

When should liveChildren() be used instead of stageChildren()?

Thank you,
Ben