aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/twig/twig/doc/filters/split.rst
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/twig/twig/doc/filters/split.rst')
-rw-r--r--vendor/twig/twig/doc/filters/split.rst53
1 files changed, 53 insertions, 0 deletions
diff --git a/vendor/twig/twig/doc/filters/split.rst b/vendor/twig/twig/doc/filters/split.rst
new file mode 100644
index 00000000..7cd2ca5b
--- /dev/null
+++ b/vendor/twig/twig/doc/filters/split.rst
@@ -0,0 +1,53 @@
1``split``
2=========
3
4.. versionadded:: 1.10.3
5 The split filter was added in Twig 1.10.3.
6
7The ``split`` filter splits a string by the given delimiter and returns a list
8of strings:
9
10.. code-block:: jinja
11
12 {{ "one,two,three"|split(',') }}
13 {# returns ['one', 'two', 'three'] #}
14
15You can also pass a ``limit`` argument:
16
17 * If ``limit`` is positive, the returned array will contain a maximum of
18 limit elements with the last element containing the rest of string;
19
20 * If ``limit`` is negative, all components except the last -limit are
21 returned;
22
23 * If ``limit`` is zero, then this is treated as 1.
24
25.. code-block:: jinja
26
27 {{ "one,two,three,four,five"|split(',', 3) }}
28 {# returns ['one', 'two', 'three,four,five'] #}
29
30If the ``delimiter`` is an empty string, then value will be split by equal
31chunks. Length is set by the ``limit`` argument (one character by default).
32
33.. code-block:: jinja
34
35 {{ "123"|split('') }}
36 {# returns ['1', '2', '3'] #}
37
38 {{ "aabbcc"|split('', 2) }}
39 {# returns ['aa', 'bb', 'cc'] #}
40
41.. note::
42
43 Internally, Twig uses the PHP `explode`_ or `str_split`_ (if delimiter is
44 empty) functions for string splitting.
45
46Arguments
47---------
48
49 * ``delimiter``: The delimiter
50 * ``limit``: The limit argument
51
52.. _`explode`: http://php.net/explode
53.. _`str_split`: http://php.net/str_split