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 /

sort() method in templates


Reply


1702 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