3434 Posts in 1026 Topics by 866 members
|Go to End|
1 October 2011 at 4:46am
I'm trying to group some items based on their groupID. So far, I managed to do with:
static $default_sort = 'groupID DESC';
Now I'm trying to read data into my template using the control-loop which works fine, showing all data sorted as defined. But now what I want, is the groupID to be displayed only if it differs from the previous value. Is there some way of saying:
// Pseudo code
if thisGroupID equals previousGroupID then
Thanks in advance,
4 October 2011 at 7:32am
Within the template control loop you have access to the methods of the current item being iterated over in the loop and the items parent ($Top.) methods. Normally I would create a Group DataObject and Item DataObject. Then assign the appropriate relationships ($has_many, $has_one, etc.). Once that is done you can loop through each Group and within the Group loop through it's Items. Beyond that I believe you'll have to write your own methods in your PHP Class to do the logic.
4 October 2011 at 9:28am
You might want to see http://doc.silverstripe.org/sapphire/en/howto/grouping-dataobjectsets/ for how to group a DataObjectSet by one of its fields.
|Go to Top|