我希望使用nochso/html-compress-twig扩展来压缩所有html、内联css和js。但这是我第一次在Twig上注册新的扩展,我有些困惑应该在我的项目中的哪里添加以下行:
$twig = new Twig_Environment($loader);
$twig->addExtension(new \nochso\HtmlCompressTwig\Extension());
我在阅读Twig的文档,但并没有给我带来太多帮助,他们只是提供了相同的示例,并添加了以下内容:
Twig does not care where you save your extension on the filesystem, as all extensions must be registered explicitly to be available in your templates.
You can register an extension by using the addExtension() method on your main Environment object:
我只想在全局启用这个扩展,并且能够在任何twig模板中使用{% htmlcompress %}{% endhtmlcompress %}