jmf / twig-spaceless
Twig extension providing a "spaceless" filter to strip whitespace between HTML tags.
1.0.0
2026-05-31 21:06 UTC
Requires
- php: ^8.3
- twig/twig: ^3.0
Requires (Dev)
- overtrue/phplint: ^9
- phpstan/phpstan: ^2
- phpstan/phpstan-strict-rules: ^2
- phpunit/phpunit: ^12|^13
- rector/rector: ^2
- squizlabs/php_codesniffer: ^4
README
Installation & Requirements
Install with Composer:
composer require jmf/twig-spaceless
Usage in Twig templates
spaceless
Strips whitespace between HTML tags (a replacement for the removed Twig spaceless tag/filter).
As a filter:
{{ '<div>\n <span>foo</span>\n</div>'|spaceless }}
{# => <div><span>foo</span></div> #}
Applied to a block:
{% apply spaceless %}
<div>
<span>foo</span>
</div>
{% endapply %}
{# => <div><span>foo</span></div> #}