JMSTwigJsBundle 不编译
JMSTwigJsBundle doesn't compile
为了优化我使用 symfony2 制作的应用程序的可能性,我选择了 JMSTwigJsBundle 以允许在前端或后端使用 twig 模板。
我用composer安装bundle和symfony(是2.7.3版本)
我开始按照教程带我添加 FOSJsRoutingBundle 和 JMSTwigJsBundle。第一个,首先安装,运行完美,但第二个给我带来了不同类型的问题,从 "Uncaught ReferenceError: goog is not defined" 开始。我通过添加以下内容解决了它:
app/autoloader.php
上的这两行如官方文档 (http://jmsyst.com/bundles/JMSTwigJsBundle) 中所述:
$loader->add('JMS', __DIR__.'/../vendor/jms/twig-js-bundle');
$loader->add('TwigJs', __DIR__.'/../vendor/jms/twig-js/src');
app/AppKernel.php
设置为以下行:
new JMS\TwigJsBundle\JMSTwigJsBundle(),
我还在 app/config.yml
中添加了这些行:
Filters:
twig_js:
resource: "%kernel.root_dir%/../vendor/jms/twig-js-bundle/JMS/TwigJsbundle/Resources/config/services.xml"
apply_to: "\.twig$"
因此,我们可以在我的 layout.html.twig
中找到以下几行
{% javascripts
'js/fos_js_routes.js'
'%kernel.root_dir%/../vendor/jms/twig-js/twig.js
'@NameSpaceNameBundle/Resources/views/customFolder/example.html.twig'%}
<script language="javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
而且,由于配置文件中的过滤器,我们不需要添加过滤器行。
这些修改来自:https://github.com/schmittjoh/JMSTwigJsBundle/pull/13 post 3
我也在这里做修改:https://github.com/schmittjoh/twig.js/issues/35 post 2 :
I found a way to fix this issue by copyng the file
/Symfony/vendor/bundles/JMS/TwigJsBundle/Resources/config/services.xml
to
/Symfony/vendor/bundles/Symfony/Bundle/AsseticBundle/Resources/config/filters/twig_js.xml
and changing the service id from twig_js.assetic_filter to
assetic.filter.twig_js.
这些修改中的每一个都给我带来了一个新的错误:
Uncaught SyntaxError: Unexpected token %
在创建的文件上 "exemple.html.twig.js:1"。有关信息,树枝文件如下所示:
{% twig_js name="example" %}
the html code
并且新文件生成的内容...与 twig 文件的内容完全相同。
所以,拜托,我必须做些什么才能让它发挥作用?谢谢
为了使其适用于任何 .twig 的编译版本,我必须将 "YUIcompressor" 添加到 app/config/config.yml
:
yui_css:
jar: "%kernel.root_dir%/Resources/java/yuicompressor.jar"
yui_js
jar: "%kernel.root_dir%/Resources/java/yuicompressor.jar"
并将适当的文件添加到关联路径。
然后我添加到 layout.html.twig
{% javascripts filter='?yui_js'
'js/fos_js_routes.js'
'%kernel.root_dir%/../vendor/jms/twig-js/twig.js
'@NameSpaceNameBundle/Resources/views/customFolder/example.html.twig'%}
<script language="javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
最后我用 app/console assets:install 和 app/console assetic:dump 检查它们是否没有问题,精神焕发并且没问题(至少对我来说是这样).
为了优化我使用 symfony2 制作的应用程序的可能性,我选择了 JMSTwigJsBundle 以允许在前端或后端使用 twig 模板。
我用composer安装bundle和symfony(是2.7.3版本)
我开始按照教程带我添加 FOSJsRoutingBundle 和 JMSTwigJsBundle。第一个,首先安装,运行完美,但第二个给我带来了不同类型的问题,从 "Uncaught ReferenceError: goog is not defined" 开始。我通过添加以下内容解决了它:
app/autoloader.php
上的这两行如官方文档 (http://jmsyst.com/bundles/JMSTwigJsBundle) 中所述:
$loader->add('JMS', __DIR__.'/../vendor/jms/twig-js-bundle');
$loader->add('TwigJs', __DIR__.'/../vendor/jms/twig-js/src');
app/AppKernel.php
设置为以下行:
new JMS\TwigJsBundle\JMSTwigJsBundle(),
我还在 app/config.yml
中添加了这些行:
Filters:
twig_js:
resource: "%kernel.root_dir%/../vendor/jms/twig-js-bundle/JMS/TwigJsbundle/Resources/config/services.xml"
apply_to: "\.twig$"
因此,我们可以在我的 layout.html.twig
中找到以下几行
{% javascripts
'js/fos_js_routes.js'
'%kernel.root_dir%/../vendor/jms/twig-js/twig.js
'@NameSpaceNameBundle/Resources/views/customFolder/example.html.twig'%}
<script language="javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
而且,由于配置文件中的过滤器,我们不需要添加过滤器行。
这些修改来自:https://github.com/schmittjoh/JMSTwigJsBundle/pull/13 post 3
我也在这里做修改:https://github.com/schmittjoh/twig.js/issues/35 post 2 :
I found a way to fix this issue by copyng the file /Symfony/vendor/bundles/JMS/TwigJsBundle/Resources/config/services.xml to /Symfony/vendor/bundles/Symfony/Bundle/AsseticBundle/Resources/config/filters/twig_js.xml and changing the service id from twig_js.assetic_filter to assetic.filter.twig_js.
这些修改中的每一个都给我带来了一个新的错误:
Uncaught SyntaxError: Unexpected token %
在创建的文件上 "exemple.html.twig.js:1"。有关信息,树枝文件如下所示:
{% twig_js name="example" %}
the html code
并且新文件生成的内容...与 twig 文件的内容完全相同。
所以,拜托,我必须做些什么才能让它发挥作用?谢谢
为了使其适用于任何 .twig 的编译版本,我必须将 "YUIcompressor" 添加到 app/config/config.yml
:
yui_css:
jar: "%kernel.root_dir%/Resources/java/yuicompressor.jar"
yui_js
jar: "%kernel.root_dir%/Resources/java/yuicompressor.jar"
并将适当的文件添加到关联路径。
然后我添加到 layout.html.twig
{% javascripts filter='?yui_js'
'js/fos_js_routes.js'
'%kernel.root_dir%/../vendor/jms/twig-js/twig.js
'@NameSpaceNameBundle/Resources/views/customFolder/example.html.twig'%}
<script language="javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
最后我用 app/console assets:install 和 app/console assetic:dump 检查它们是否没有问题,精神焕发并且没问题(至少对我来说是这样).