funcphp/twig-compress

There is no license information available for the latest version (dev-master) of this package.

Output compressor for twig

dev-master 2017-12-26 14:53 UTC

This package is not auto-updated.

Last update: 2024-05-21 16:38:46 UTC


README

outputcompressorfortwigbutbetterthan{% spaceless %}

install

download repo

$ composer require funcphp/twig-compress "dev-master"
without symfony:
// add extension to your twig engine
$twigEngine->addExtension(new \Func\Twig\CompressExtension());
with symfony:

enable bundle

$bundles = [
    ...
    new \Func\CompressBundle\FuncCompressBundle(),
    ...
];

examples

basic usage

{% compress %}
<html>
    <head>
        <style>
            body {
                background: #fcc200;
            }
        </style>
        <script>
            alert('hello')
        </script>
    </head>
</html>
{% endcompress %}

output:

<html><head><style> body { background: #fcc200; } </style><script> alert('hello') </script></head></html>

use with secure option

this does the same thing with {% spaceless %}

{% compress not secure %}
<html>
    <head>
        <style>
            body {
                background: #fcc200;
            }
        </style>
        <script>
            alert('hello')
        </script>
    </head>
</html>
{% endcompress %}

you can use {% compress secure=false %} instead of {% compress not secure %}

output:

<html><head><style>
            body {
                background: #fcc200;
            }
        </style><script>
            alert('hello')
        </script></head></html>