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

1334 Views

Avatar
Juanitou

29 September 2009 at 7:06am (Last edited: 29 September 2009 7:08am), Community Member, 323 Posts

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