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.

Data Model Questions /

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

Loop children


Go to End


2 Posts   1491 Views

Avatar
suntrop

Community Member, 141 Posts

10 December 2016 at 2:15am

After updating from 3.1 to 3.5 this function will output even draft pages

function FilteredChildren($filter = '"SiteTree"."Sort" ASC') {
		return DataObject::get('Page', "ParentID = {$this->ID}", $filter);
	}

I tried $this->Children(); as well, but it only displays two of 8 pages.

The template has just a <% loop FilteredChildren %> in it.

Avatar
Kirk

Community Member, 67 Posts

15 December 2016 at 3:58pm

Edited: 15/12/2016 3:58pm

I would not even use a custom method as you can loop through the children directly in the template

<% loop $Children.Sort(Sort ASC) %>
<% end_loop %>