funcphp/twig-compress

该包最新版本(dev-master)没有可用的许可信息。

twig 的输出压缩器

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

This package is not auto-updated.

Last update: 2024-09-24 18:11:22 UTC


README

输出压缩器用于 twig,但比 {% spaceless %} 更好

安装

下载仓库

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

启用扩展包

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

示例

基本用法

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

输出

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

使用安全选项

这和 {% spaceless %} 做的是同样的事情

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

您可以使用 {% compress secure=false %} 替代 {% compress not secure %}

输出

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