$context
$context : array
Template tag <code>regroup</code>.
Regroup a list of alike objects by a common attribute.
This complex tag is best illustrated by use of an example: say that people is a list of people represented by arrays with first_name, last_name, and gender keys:
$people = array(
array('first_name' => 'George',
'last_name' => 'Bush',
'gender' => 'Male'),
array('first_name' => 'Bill',
'last_name' => 'Clinton',
'gender' => 'Male'),
array('first_name' => 'Margaret',
'last_name' => 'Thatcher',
'gender' => 'Female'),
array('first_name' => 'Condoleezza',
'last_name' => 'Rice',
'gender' => 'Female'),
array('first_name' => 'Pat',
'last_name' => 'Smith',
'gender' => 'Unknow'),
);
...and you'd like to display a hierarchical list that is ordered by gender, like this:
You can use the {regroup} tag to group the list of people by gender. The following snippet of template code would accomplish this:
{regroup $people, 'gender', 'gender_list'}
Let's walk through this example. {regroup} takes three arguments: the object (array or instance of Pluf_Model or any object) you want to regroup, the attribute to group by,and the name of the resulting object. Here, we're regrouping the people list by the gender attribute and calling the result gender_list. The result is assigned in a context varible of the same name $gender_list.
{regroup} produces a instance of ArrayObject (in this case, $gender_list) of group objects. Each group object has two attributes:
Note that {regroup} does not order its input!
Based on concepts from the Django regroup template tag.