Yaffs site version 1.1
[yaffs-website] / vendor / twig / twig / doc / filters / trim.rst
1 ``trim``
2 ========
3
4 .. versionadded:: 1.32
5     The ``side`` argument was added in Twig 1.32.
6
7 .. versionadded:: 1.6.2
8     The ``trim`` filter was added in Twig 1.6.2.
9
10 The ``trim`` filter strips whitespace (or other characters) from the beginning
11 and end of a string:
12
13 .. code-block:: jinja
14
15     {{ '  I like Twig.  '|trim }}
16
17     {# outputs 'I like Twig.' #}
18
19     {{ '  I like Twig.'|trim('.') }}
20
21     {# outputs '  I like Twig' #}
22
23     {{ '  I like Twig.  '|trim(side='left') }}
24
25     {# outputs 'I like Twig.  ' #}
26
27     {{ '  I like Twig.  '|trim(' ', 'right') }}
28
29     {# outputs '  I like Twig.' #}
30
31 .. note::
32
33     Internally, Twig uses the PHP `trim`_, `ltrim`_, and `rtrim`_ functions.
34
35 Arguments
36 ---------
37
38 * ``character_mask``: The characters to strip
39
40 * ``side``: The default is to strip from the left and the right (`both`) sides, but `left`
41   and `right` will strip from either the left side or right side only
42
43 .. _`trim`: http://php.net/trim
44 .. _`ltrim`: http://php.net/ltrim
45 .. _`rtrim`: http://php.net/rtrim