如何使用 Twig 缩小 HTML? [英] How can I minify HTML with Twig?

查看:27
本文介绍了如何使用 Twig 缩小 HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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 }}

这篇关于如何使用 Twig 缩小 HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆