a SensioLabs Product

The flexible, fast, and secure
template engine for PHP

Filters » trim

Table of Contents

Questions & Feedback

License

Twig documentation is licensed under the new BSD license.

trim

New in version 1.6.2: The trim filter was added in Twig 1.6.2.

The trim filter strips whitespace (or other characters) from the beginning and end of a string:

1
2
3
4
5
6
7
{{ '  I like Twig.  '|trim }}

{# outputs 'I like Twig.' #}

{{ '  I like Twig.'|trim('.') }}

{# outputs '  I like Twig' #}

Note

Internally, Twig uses the PHP trim function.

Arguments

  • character_mask: The characters to strip
This website is powered by PHP and Twig. The Twig logo is © 2010-2016 SensioLabs