Jump to:

3435 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » <% control Children %> and Object->Children() only return when shown in Menu?

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

Page: 1
Go to End
Author Topic: 1095 Views
  • MikeOne
    Avatar
    Community Member
    40 Posts

    <% control Children %> and Object->Children() only return when shown in Menu? Link to this post

    Hi,

    I'm working on some code to generate a Tab Container with Tabs (which will then be rendered using jQuery). because this will be Tab content, it should not show in Menu and Search and so on so I switched this off in the defaults for those page types (TabContainer and TabContent).

    Now I went to work on the coding and found that my tabs (as children of the tabscontainer) did not show up if I did a <% control Children %> in the TabsContainer template or in the controller for that page (as object->Children())... I found this was due because in the CMS, the tickbox 'Show In Menu' was off... Seemed very weird to me and took me ages to find out...

    Is this by design? And if yes - WHY? It would make sense to exclude those pages that are set not to show in menu if you <% control Menu %> but it seems, they completely dissapear from the parent object..

    The only way to get to these children was by accessing the dataobject on the controller of the TabsContainer:

    public function getTabs(){

          return DataObject::get("TabContent", "ParentID = $this->ID");

    }

    It works - but still - this seems really counterintuitive and not very MVC to me..

  • Juanitou
    Avatar
    Community Member
    323 Posts
  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: <% control Children %> and Object->Children() only return when shown in Menu? Link to this post

    +1 what Junaitou said.

    <% control Children %> returns a set that is filtered through canView() on each page. <% control AllChildren %> will return the children, disregarding canView().

  • MikeOne
    Avatar
    Community Member
    40 Posts

    Re: <% control Children %> and Object->Children() only return when shown in Menu? Link to this post

    Ah - that makes more sense ;-) Thanks!

    Unfortunately, I'm getting a 'White Screen Of Death' if I use AllChildren - I'll investigate a bit more...

  • MikeOne
    Avatar
    Community Member
    40 Posts

    Re: <% control Children %> and Object->Children() only return when shown in Menu? Link to this post

    I must have made a Typo when I tried AllChildren yesterday, as it does seem to work now..

    Brilliant - thanks!

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