Tests
Test: array
Template
{% for item in items|reverse %}
{{ item }}
{% endfor %}
Data
{
"items": [1, 2, 3, 4]
}
Output Django (error) v1.10.1
Invalid filter: 'reverse'
Output Jinja2 v2.8.0
4
3
2
1
Output Liquid v3.0.6
1
2
3
4
Output Nunjucks v2.5.0
4
3
2
1
Output Swig v1.4.2
4
3
2
1
Output Twig v1.24.2
4
3
2
1
Output Twigjs v0.9.5
4
3
2
1
Test: number
Template
{{ 1234|reverse }}
Output Django (error) v1.10.1
Invalid filter: 'reverse'
Output Jinja2 (error) v2.8.0
argument must be iterable
Output Liquid v3.0.6
1234
Output Nunjucks (error) v2.5.0
(no output)
Output Swig v1.4.2
1234
Output Twig v1.24.2
4321
Output Twigjs (error) v0.9.5
(no output)
Test: object-default
Template
{% for key, value in mapping|reverse %}
{{ key }}: {{ value }}
{% endfor %}
Data
{
"mapping": { "1": "a", "2": "b", "3": "c" }
}
Output Django (error) v1.10.1
Invalid filter: 'reverse'
Output Jinja2 (error) v2.8.0
need more than 1 value to unpack
Output Liquid (error) v3.0.6
Liquid syntax error: Syntax Error in 'for loop' - Valid syntax: for [item] in [collection]
Output Nunjucks (error) v2.5.0
(no output)
Output Swig v1.4.2
0: 3
1: 2
2: 1
Output Twig v1.24.2
0: c
1: b
2: a
Output Twigjs v0.9.5
3: c
2: b
1: a
Test: object-preserve-keys
Template
{% for key, value in mapping|reverse(true) %}
{{ key }}: {{ value }}
{% endfor %}
Data
{
"mapping": { "1": "a", "2": "b", "3": "c" }
}
Output Django (error) v1.10.1
Invalid filter: 'reverse'
Output Jinja2 (error) v2.8.0
do_reverse() takes exactly 1 argument (2 given)
Output Liquid (error) v3.0.6
Liquid syntax error: Syntax Error in 'for loop' - Valid syntax: for [item] in [collection]
Output Nunjucks (error) v2.5.0
(no output)
Output Swig v1.4.2
0: 3
1: 2
2: 1
Output Twig v1.24.2
3: c
2: b
1: a
Output Twigjs v0.9.5
3: c
2: b
1: a
Test: string
Template
{{ '1234'|reverse }}
Output Django (error) v1.10.1
Invalid filter: 'reverse'
Output Jinja2 v2.8.0
4321
Output Liquid v3.0.6
1234
Output Nunjucks v2.5.0
4321
Output Swig v1.4.2
4321
Output Twig v1.24.2
4321
Output Twigjs v0.9.5
4321