基于Symfony2环境的无空间响应
我正在寻找的是基于当前 Symfony 环境为整个 Response
对象启用/禁用 {% spaceless %}{% endspaceless %}
包装器的方法。我想我应该听 kernel.view
事件并修改那里的响应,但我做不到。
这样做的原因是,最好使用所有这些空间进行调试,但应将其缩小以供生产使用。
有人做过这个吗?
What I am looking is the way to enable/disable {% spaceless %}{% endspaceless %}
wrapper for the whole Response
object based on current Symfony environment. I think I should listen to kernel.view
event and modify response there, but I can't make it.
The reason for this is that it is better to debug with all those spaces, but keep it minified for production usage.
Has anybody done this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
spaceless
是一个 Twig 标签,响应永远不会知道它。您无法轻松禁用它,因为它是
Twig_Extension_Core
的一部分,并且没有选项可以禁用它。你必须找到另一种方法。
也许直接来自您的模板(使用或不使用它取决于环境)。
The
spaceless
is a Twig tag, the response will never know about it.You can't easily disable it as it's part of the
Twig_Extension_Core
and there is no option to disable it.You have to find another way.
Maybe directly from your template (using it or not the depending on the environnement).
在您的包中实现 ResponseListener:
然后在 services.yml 中声明:
Implement a ResponseListener in your bundle:
Then declare in services.yml: