N°5725 - Twig update 'filter', 'map' and 'reduce' filters

This commit is contained in:
Eric Espie
2022-12-07 11:59:34 +01:00
parent dad22f6f83
commit cda017fa4f
3 changed files with 71 additions and 20 deletions

View File

@@ -19,7 +19,7 @@
["touch+\/tmp\/test+"]
<div>[34, 36, 38, 40, 42]|filter(v => v > 38)|join(', ')</div>
40, 42
[34,36,38,40,42]
<div>app.request.server.all|join(',')</div>
@@ -28,16 +28,16 @@
<div>[0]|reduce('system','echo')</div>
[0]
0
<div>[1, 2, 3]|reduce((carry, v) => carry + v)</div>
6
1, 2, 3
<div>['echo']|map('system')|join</div>
[&quot;echo&quot;]
echo
<div>{"Bob": "Smith", "Alice": "Dupond"}|map((value, key) => "#{key} #{value}")|join(', ')</div>
Bob Smith, Alice Dupond
Smith, Dupond
<div>['echo',1]|sort('system')|join</div>
echo1

View File

@@ -28,11 +28,11 @@
{{ self }}
<div>[0]|reduce('system','echo')</div>
{{ [0]|reduce('system','echo') }}
{{ [0]|reduce('system','echo')|join(', ') }}
<div>[1, 2, 3]|reduce((carry, v) => carry + v)</div>
{% set numbers = [1, 2, 3] %}
{{ numbers|reduce((carry, v) => carry + v) }}
{{ numbers|reduce((carry, v) => carry + v)|join(', ') }}
<div>['echo']|map('system')|join</div>
{{ ['echo']|map('system')|join }}