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.

Archive /

Our old forums are still available as a read-only archive.

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

sorting in the control Children


Go to End


2 Posts   2950 Views

Avatar
grandsapin1673

Community Member, 12 Posts

30 April 2008 at 10:59am

Hello,
After reading tutorials and a few docs about data managment, I wonder if this is possible to sort data at template level, typicaly in the
<% control Children %>
tag.
I realize that this would be a little agains MVC model...
Many thanks,
Eric

Avatar
Sean

Forum Moderator, 922 Posts

30 April 2008 at 5:06pm

I'm not quite sure you can do that in the templates, at least I've never investigated far enough to do so. Is there any reason to go against the MVC model?

You may, be able to do this, in your model class:

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

Then you could go:

<% control FilteredChildren('Title DESC') %>

If you leave the parameter out, it uses "ID DESC" - the default. However, I've not tested this, the templating system might not allow it.

Cheers,
Sean