Kev*_*ell 2 php symfony twig twig-extension
我想使用nochso/html-compress-twig 扩展来压缩所有 html、内联 css 和 js。但这是我第一次在 Twig 上注册一个新扩展,我对应该在哪里添加以下几行感到有些困惑我的项目:
$twig = new Twig_Environment($loader);
$twig->addExtension(new \nochso\HtmlCompressTwig\Extension());
Run Code Online (Sandbox Code Playgroud)
我正在阅读 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:
Run Code Online (Sandbox Code Playgroud)
我只想全局启用扩展并能够{% htmlcompress %}{% endhtmlcompress %}在任何树枝模板中使用
Ala*_*blo 11
您可以通过以下方式将您的树枝扩展注册为标记服务:
services:
htmlcompress:
class: '\nochso\HtmlCompressTwig\Extension'
tags:
- { name: twig.extension }
Run Code Online (Sandbox Code Playgroud)