问题描述
在 Symfony2 中,我包含了许多标准 JavaScript 文件,并使用 Twig YUI 过滤器压缩到一个文件中,如下所示:
In Symfony2 I have a number of standard JavaScript files I include and compress into one file using the Twig YUI filter like so:
{% javascripts
'@WebIlluminationShopBundle/Resources/public/js/jquery.js'
'@WebIlluminationShopBundle/Resources/public/js/ui.js'
'@WebIlluminationShopBundle/Resources/public/js/tools.js'
'@WebIlluminationShopBundle/Resources/public/js/overlay.js'
'@WebIlluminationShopBundle/Resources/public/js/uniform.js'
'@WebIlluminationShopBundle/Resources/public/js/slider.js'
'@WebIlluminationShopBundle/Resources/public/js/global.js'
output='js/shop-compressed.js' filter='yui_js' %}
<script src="{{ asset_url }}" type="text/javascript"></script>
{% endjavascripts %}
然后在我的 Twig 模板中包含特定的 JavaScript Twig 文件,这些文件将数据作为来自控制器的变量传递给它们:
Within my Twig templates I then include specific JavaScript Twig files, which have data passed to them as variables from the controller:
{% include 'SomeCompanySomeBundle:ControllerName:testScript.js.twig' with {'variable1': variable1, 'variable2': variable2} %}
有没有办法像压缩我使用 YUI 过滤器使用的主要 JavaScript 文件一样压缩这个 JavaScript?
Is there a way to compress this JavaScript like I would the main JavaScript files I use using the YUI filter?
这可能是不可能的,但只是想知道是否肯定有新人.
It may not be possible, but just wondered if someone new for sure.
推荐答案
Twig 生成的 JS 文件需要在每次请求时使用 Twig 上下文刷新,这是不可能的!
Twig generated JS files needs to be refreshed with Twig context on each request, son it's not possible !
这篇关于你如何压缩 Symfony2 中包含的 Twig JavaScript 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!