我想使用nochso/html-compress-twig extension来压缩所有的html,内联css和js.但是这是我第一次在Twig上注册一个新的扩展,并且我有点困惑应该在哪里添加以下行在我的项目:在Symfony中注册Twig扩展
$twig = new Twig_Environment($loader);
$twig->addExtension(new \nochso\HtmlCompressTwig\Extension());
我读了枝条的文档,但他们把同样的例子,只是添加它并没有帮助我很多的以下内容:
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:
我只希望能够延长全球范围内并能够使用{% htmlcompress %}{% endhtmlcompress %}
任何树枝模板
你最好遵循Symfony特定文档在这里:http://symfony.com/doc/current/templating/twig_extension.html –
不要忘记选择正确的symfony版本,您也正在使用 –