# group\_by

Source: https://zotonic.com/docs/1939/group_by

URI: https://zotonic.com/id/1939

Language: en



Groups items of a list by a property.

An item can be an *id*, a *proplist* or a *map*.

- When the item is an integer then it is assumed to be the *id* of a resource.
- This is especially useful for grouping items in for-loops.

For example:

```django
{% for grp in value|group_by:"a" %} ... loop over grp ... {% endfor %}
```

When value is the three element list:

```django
[
 [{a, 1}, {b, 1}],
 [{a, 1}, {b, 2}],
 [{a, 2}, {b, 3}]
]
```

then the output of group\_by “a” will be the two element list:

```django
[
 [ [{a, 1}, {b, 1}], [{a, 1}, {b, 2}] ],
 [ [{a, 2}, {b, 3}] ]
].
```

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/1939?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/1939?language=en>)
