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.

Template Questions /

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

sort() method in templates


Go to End


4506 Views

Avatar
Juanitou

Community Member, 323 Posts

29 September 2009 at 7:06am

Edited: 29/09/2009 7:08am

Hi!

Some pages of a site have related ThemePages (many_many as Themes => ThemePage). I can show them easily with:

<% control Themes %>

Only, they are not sorted as I would like to. I’m certainly doing something stupid, since using:

<% control Themes.sort(ID) %>

…renders nothing, but this works:

function sortedThemes() {
	$themes = $this->Themes();
	$themes->sort('ID');
	return $themes;
}

---

<% control sortedThemes %>

Well, I know I can use $default_sort = '`SiteTree`.ID', but I’m curious… :)

Thanks in advance,
Juan