reverse
¶
The reverse
filter reverses a sequence, a mapping, or a string:
逆フィルターは、シーケンス、マッピング、または文字列を逆にします。
1 2 3 4 5 6 7 |
{% for user in users|reverse %}
...
{% endfor %}
{{ '1234'|reverse }}
{# outputs 4321 #}
|
Tip
ヒント
For sequences and mappings, numeric keys are not preserved. To reverse
them as well, pass true
as an argument to the reverse
filter:
シーケンスとマッピングの場合、数値キーは保持されません。それらを逆にするには、引数として true を逆フィルターに渡します。
1 2 3 4 5 6 7 8 9 10 11 |
{% for key, value in {1: "a", 2: "b", 3: "c"}|reverse %}
{{ key }}: {{ value }}
{%- endfor %}
{# output: 0: c 1: b 2: a #}
{% for key, value in {1: "a", 2: "b", 3: "c"}|reverse(true) %}
{{ key }}: {{ value }}
{%- endfor %}
{# output: 3: c 2: b 1: a #}
|
Note
ノート
It also works with objects implementing the Traversable interface.
また、Traversable インターフェースを実装するオブジェクトでも機能します。
Arguments ¶
preserve_keys
: Preserve keys when reversing a mapping or a sequence.preserve_keys: マッピングまたはシーケンスを逆にするときにキーを保持します。