Easy whitespace trimming with Twig

Categories
Today I learned Web Development

When using the Twig templating engine for PHP you might have used the trim filter to trim away any possible existing blanks at the beginning and end of a string:

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

{# outputs 'I like Twig.' #}

Another way to trim out whitespaces is by using the – modifier:

<li>
    {{- value }}    </li>
{# outputs '<li>no spaces    </li>' #}

Dein Kommentar

Hinweis: Deine E-Mailadresse wird nicht veröffentlicht.

This site uses Akismet to reduce spam. Learn how your comment data is processed.