简体   繁体   English

在Symfony 2中通过Twig包含javascript dojo文件

[英]Include javascript dojo files via Twig in Symfony 2

I try to achieve a simple goal: add developped dojo classes in a symfony2 html page with Twig. 我尝试实现一个简单的目标:使用Twig在symfony2 html页面中添加开发的dojo类。

I had read a lot of documentation on assetic, and i found two types of method to include assets: 我阅读了很多有关资产的文档,发现包含资产的两种方法:

The first one with the asset() twig function. 第一个带有asset()树枝函数的函数。 And the second one with the "javascripts" tag. 第二个带有“ javascripts”标签。

The assets function is used to include files which are stored in the web/ folder whereas javascripts tag load files which are stored in the resource folder of the current bundle. 资产功能用于包含存储在web /文件夹中的文件,而javascripts标记加载存储在当前捆绑包的资源文件夹中的文件。

My dojo classes files are stored in the resource folder of a bundle, so i tried to load them with a javascripts tag like this: 我的dojo类文件存储在分发包的资源文件夹中,因此我尝试使用javascripts标签加载它们,如下所示:

{% javascripts '@MyBundle/Resources/public/js/MyClass.js' output= 'js/myBundle/MyClass.js'   %}
  <script type='text/javascript' src='{{ asset_url }}'></script>
{% endjavascripts %}  

And it work, my file is successfully included, unfortunately the name is not "MyClass.js" but "MyCmass_MyClass_1.js". 它可以正常工作,我的文件已成功包含在内,不幸的是,名称不是“ MyClass.js”,而是“ MyCmass_MyClass_1.js”。 I have executed the assetic:dump --env=prod command but my file name still "MyCmass_MyClass_1.js" 我已经执行了assetic:dump --env = prod命令,但是我的文件名仍然是“ MyCmass_MyClass_1.js”

What can I do to correct this ? 我该怎么做才能纠正这个问题?

(I tried to delete the cache, relaunch my server in prod/dev, launch the assetic command with the dev env, and no change). (我尝试删除缓存,在prod / dev中重新启动服务器,使用dev env启动资产命令,并且没有任何更改)。

以生产模式访问您的网站: yoursite.com/app.php而不是yoursite.com/app_dev.php ,或将您的网络服务器指向Web文件夹中的正确文件: web/app.php

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

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