a SensioLabs Product

The flexible, fast, and secure
template engine for PHP

You are reading the documentation for Twig 2.x. Switch to the documentation for Twig 1.x.

Table of Contents

Questions & Feedback

License

Twig documentation is licensed under the new BSD license.

trim

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
Website powered by Symfony and Twig, deployed on
The Twig logo is © 2010-2017 SensioLabs