Tests
Test: attribute
Template
{% for type, items in items | groupby('type') %}
{{ type }}:
{% for item in items %}{{ item.name }} {% endfor %}
{% endfor %}
Data
{
"items": [
{
"name": "james",
"type": "green"
},
{
"name": "john",
"type": "blue"
},
{
"name": "jim",
"type": "blue"
},
{
"name": "jessie",
"type": "green"
}
]
}
Output Django (error) v1.10.1
'for' statements should use the format 'for x in y': for type, items in items | groupby('type')
Output Jinja2 v2.8.0
blue:
john jim
green:
james jessie
Output Liquid (error) v3.0.6
Liquid syntax error: Syntax Error in 'for loop' - Valid syntax: for [item] in [collection]
Output Nunjucks v2.5.0
green:
james jessie
blue:
john jim
Output Swig (error) v1.4.2
Invalid filter "groupby".
Output Twig (error) v1.24.2
Unknown "groupby" filter.
Output Twigjs (error) v0.9.5
Unable to find filter groupby