Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » liveChildren() vs. stageChildren()

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1167 Views
  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    liveChildren() vs. stageChildren() Link to this post

    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

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: liveChildren() vs. stageChildren() Link to this post

    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()

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: liveChildren() vs. stageChildren() Link to this post

    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

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: liveChildren() vs. stageChildren() Link to this post

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

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: liveChildren() vs. stageChildren() Link to this post

    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

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