21492 Posts in 5783 Topics by 2621 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1100 Views |
-
Sorting many_many relation in front end

16 October 2009 at 12:14am Last edited: 16 October 2009 12:15am
Like the title say I've got a many_many relation and when I show the objects in the front end they need to be sorted by product ID numbers that the client sets. But when I use <% control Products %> they are called up in the order they were created.
Is there away of achieving this that I haven't found or will I have to create a custom method that calls Dataobject::get().
-
Re: Sorting many_many relation in front end

16 October 2009 at 1:20pm
You can do this:
<% if Products %>
$Products.sort(Price)
<% control Products %>
// content
<% end_control %>
<% end_if %>But due to an annoying limitation of SSViewer, you can't set the order (it is ascending by default). For anything more complicated you'll need your own method.
-
Re: Sorting many_many relation in front end

16 October 2009 at 3:17pm
Thank you, that should do just what I need.
Is there an entry in the documentation that covers this or other built in functions that can be applied in the template?
-
Re: Sorting many_many relation in front end

17 October 2009 at 1:08am
Thanks dalesaurus, that is a good reference but there's nothing there about a sort() method. Just a reference to the Sort field in the Sitetree table of the database.
I've been experimenting and found that the method is coming from the DataObjectSet class which should help answer most of the questions I have. I expect that I'll be back if it doesn't.
Anyone know what other core classes I can expect to show up in the templates? I'm assuming their methods would be available in the same way.
| 1100 Views | ||
|
Page:
1
|
Go to Top |



