如何使用Twig缩小HTML

如何使用Twig缩小HTML

本文介绍了如何使用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?

推荐答案

这可能对您没有什么帮助.

This may help you little.

使用html-compress-twig,您可以将html,css,js压缩到一个包中.使用composer安装composer require nochso/html-compress-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 nochso\HtmlCompressTwig\Extension());
return $ojt_theme;});

最后转到您的模板文件,添加此代码.

finally go to your template file add this code.

{% htmlcompress %} ....your coding... {% endhtmlcompress %}
{{ htmlcompress('<ul> <li>') }}
{{ '<ul> <li>'|htmlcompress }}

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

08-14 18:27