Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame^] | 1 | ``join`` |
| 2 | ======== |
| 3 | |
| 4 | The ``join`` filter returns a string which is the concatenation of the items |
| 5 | of a sequence: |
| 6 | |
| 7 | .. code-block:: twig |
| 8 | |
| 9 | {{ [1, 2, 3]|join }} |
| 10 | {# returns 123 #} |
| 11 | |
| 12 | The separator between elements is an empty string per default, but you can |
| 13 | define it with the optional first parameter: |
| 14 | |
| 15 | .. code-block:: twig |
| 16 | |
| 17 | {{ [1, 2, 3]|join('|') }} |
| 18 | {# outputs 1|2|3 #} |
| 19 | |
| 20 | A second parameter can also be provided that will be the separator used between |
| 21 | the last two items of the sequence: |
| 22 | |
| 23 | .. code-block:: twig |
| 24 | |
| 25 | {{ [1, 2, 3]|join(', ', ' and ') }} |
| 26 | {# outputs 1, 2 and 3 #} |
| 27 | |
| 28 | Arguments |
| 29 | --------- |
| 30 | |
| 31 | * ``glue``: The separator |
| 32 | * ``and``: The separator for the last pair of input items |