Server IP : 23.254.227.96 / Your IP : 216.73.216.7 Web Server : Apache/2.4.62 (Unix) OpenSSL/1.1.1k System : Linux hwsrv-1277026.hostwindsdns.com 4.18.0-477.13.1.el8_8.x86_64 #1 SMP Tue May 30 14:53:41 EDT 2023 x86_64 User : viralblo ( 1001) PHP Version : 8.1.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/local/cwpsrv/var/services/twig/doc/filters/ |
Upload File : |
``reverse`` =========== The ``reverse`` filter reverses a sequence, a mapping, or a string: .. code-block:: jinja {% 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: .. code-block:: jinja {% 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. Arguments --------- * ``preserve_keys``: Preserve keys when reversing a mapping or a sequence. .. _`Traversable`: http://php.net/Traversable