Assetic Add file located in app/Resources/js

半城伤御伤魂 提交于 2019-12-24 00:29:23

问题


I am creating a bundle that requires a 3rd party js file. According to the documentation:

http://symfony.com/doc/current/cookbook/bundles/best_practices.html#vendors

Bundles should not contain 3rd party code. Since the bundle is only used in one part of the site I dont want to include it in my base template file - I want to call it from the twig file, but I am running into a problem there.

All of the demos for including js seem to reference a bundle name, but I have placed my js in app/Resources/public/js

If I use:

{% javascripts 
    "public/js/jquery.fileupload.js" %}
    <script src="{{ asset_url }}" type="text/javascript"></script>
{% endjavascripts %}

It looks in the web directory. Is there any way to use the app dir where all of my other js files live? I'm trying to follow best practices where feasible, but I would really like to keep my js in one place for simplicity, thanks for reading!


回答1:


You can do it by symlinking the Public directory in app/Resources. It's kinda messy but it should work.

On *nix, you could run:

cd ROOT_TO_YOUR_PROJECT/web/bundles
ln -s ../../app/Resources/Public common 

Basically, you are creating common symlink that points to you Public directory.

Then:

{% javascripts 
    "bundles/common/js/jquery.fileupload.js" %}
    <script src="{{ asset_url }}" type="text/javascript"></script>
{% endjavascripts %}



回答2:


This sounds related to a bug in Symfony's assetic. When you run app/console assetic:dump it doesn't base itself in the web folder, it uses the current folder. See: https://github.com/kriswallsmith/assetic/issues/202



来源:https://stackoverflow.com/questions/20125289/assetic-add-file-located-in-app-resources-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!