由网友(卖萌失败)分享简介:我正在使用 Twig,我希望能够缩小 HTML 输出.我该怎么做呢?我尝试了 {% spaceless %},但这需要将其添加到我的所有模板中.我可以在 Twig 引擎中添加缩小吗?I'm using Twig and I'd like to be able to minify the HTML output. Ho...
我正在使用 Twig,我希望能够缩小 HTML 输出.我该怎么做呢?我尝试了 {% spaceless %}
,但这需要将其添加到我的所有模板中.我可以在 Twig 引擎中添加缩小吗?
I'm using Twig and I'd like to be able to minify the HTML output. How do I do this? I tried {% spaceless %}
, but that requires adding that to all my templates. Can I add minification within the Twig engine?
推荐答案
这可能对你帮助不大.
使用 html-compress-twig 可以将 html、css、js 压缩到一个包中.使用 composer 安装 composer require nochso/html-compress-twig
并且必须通过 twig 添加 Extension使用此代码.
use html-compress-twig you can compress html,css,js in one package.use composer to install composer require nochso/html-compress-twig
and you have to add Extension with twig by using this code.
$app->extend('twig_theme', function($twig_theme, $ojt) {
$twig_theme->addExtension(new nochsoHtmlCompressTwigExtension());
return $ojt_theme;});
最后去你的模板文件添加这段代码.
finally go to your template file add this code.
{% htmlcompress %} ....your coding... {% endhtmlcompress %}
{{ htmlcompress('<ul> <li>') }}
{{ '<ul> <li>'|htmlcompress }}
相关推荐
最新文章