简体   繁体   English

JMSTwigJsBundle无法编译

[英]JMSTwigJsBundle doesn't compile

In a search to optimize the possibility of my application made with symfony2, I choose the JMSTwigJsBundle to allow the usage of twig template both frontend or backend. 为了优化使用symfony2制作应用程序的可能性,我选择了JMSTwigJsBundle以允许使用前端或后端的树枝模板。

I use composer to install bundles and symfony (it is the 2.7.3 version) 我使用composer安装bundles和symfony(它是2.7.3版本)

I began to follow a tutorial who bring me to add both FOSJsRoutingBundle and JMSTwigJsBundle. 我开始遵循一个教程,他带我添加了FOSJsRoutingBundle和JMSTwigJsBundle。 The first one, installed first, work perfectly, but the second brought me different kinds of problem, beginning with "Uncaught ReferenceError: goog is not defined". 第一个安装在第一个,可以完美运行,但是第二个给我带来了各种问题,始于“ Uncaught ReferenceError:goog未定义”。 I resolved it by adding the following content : 我通过添加以下内容解决了该问题:

these two lines on app/autoloader.php as described in the official documentation ( http://jmsyst.com/bundles/JMSTwigJsBundle ): 如官方文档( http://jmsyst.com/bundles/JMSTwigJsBundle )中所述,这是app/autoloader.php上的这两行:

$loader->add('JMS', __DIR__.'/../vendor/jms/twig-js-bundle');
$loader->add('TwigJs', __DIR__.'/../vendor/jms/twig-js/src');

The app/AppKernel.php is set with the following line : 使用以下行设置app/AppKernel.php

new JMS\TwigJsBundle\JMSTwigJsBundle(),

I also add to my app/config.yml these lines : 我还将这些行添加到我的app/config.yml

Filters:
twig_js:
resource: "%kernel.root_dir%/../vendor/jms/twig-js-bundle/JMS/TwigJsbundle/Resources/config/services.xml"
apply_to: "\.twig$"

So, we can found inside my layout.html.twig the following lines 因此,我们可以在我的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 %}

And, thank to the filters on the config file, we don't need to add the filter line. 并且,感谢配置文件中的过滤器,我们不需要添加过滤器行。

These modifications are from : https://github.com/schmittjoh/JMSTwigJsBundle/pull/13 post 3 这些修改来自: https : //github.com/schmittjoh/JMSTwigJsBundle/pull/13第三篇

I also do modifications presentend here : https://github.com/schmittjoh/twig.js/issues/35 post 2 : 我也在这里做了修改presentend: 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. 通过将文件/Symfony/vendor/bundles/JMS/TwigJsBundle/Resources/config/services.xml复制到/ Symfony / vendor / bundles / Symfony / Bundle / AsseticBundle / Resources / config / filters /,我找到了解决此问题的方法twig_js.xml并将服务ID从twig_js.assetic_filter更改为assetic.filter.twig_js。

Every of theses modifications bring me to a new error : 这些修改都给我带来了一个新的错误:

Uncaught SyntaxError: Unexpected token % 未捕获到的SyntaxError:意外令牌%

on the created file "exemple.html.twig.js:1". 在创建的文件“ exemple.html.twig.js:1”上。 For information, the twig file looks like : 有关信息,树枝文件如下所示:

{% twig_js name="example" %}
the html code

And the content generated on the new file is... exactly the same content than the twig's file. 而且,新文件上生成的内容与树枝文件完全相同。

So, please, what did I have to do to make it work ? 所以,请问我要怎么做才能使其正常工作? Thank's 谢谢

To make it work to and have a compiled version of any .twig, I had to include the "YUIcompressor" to the app/config/config.yml : 为了使其能够工作并具有任何.twig的编译版本,我必须在app/config/config.yml包括“ YUIcompressor”:

yui_css:
jar: "%kernel.root_dir%/Resources/java/yuicompressor.jar"
yui_js
jar: "%kernel.root_dir%/Resources/java/yuicompressor.jar"

and add the appropriate file to the associate path. 并将适当的文件添加到关联路径。

Then I add to the layout.html.twig 然后我添加到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 %}

Finally I use the app/console assets:install and app/console assetic:dump to check if they're is nothing wrong, refreshed and it was ok (at least for me). 最后,我使用app / console资产:install和app / console资产:dump来检查它们是否没有问题,刷新并确定(至少对我而言)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM