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.

Template Questions

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


Reply

5 Posts   1115 Views

Avatar
MikeOne

22 October 2009 at 5:31am Community Member, 40 Posts

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

Avatar
Juanitou

22 October 2009 at 11:45am Community Member, 323 Posts

Hi!

Try AllChildren.

Avatar
Willr

22 October 2009 at 4:54pm Forum Moderator, 5511 Posts

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

Avatar
MikeOne

22 October 2009 at 10:34pm Community Member, 40 Posts

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

Avatar
MikeOne

22 October 2009 at 10:45pm (Last edited: 22 October 2009 10:45pm), Community Member, 40 Posts

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

Brilliant - thanks!