Assetic 添加文件位于 app/Resources/js [英] Assetic Add file located in app/Resources/js

查看:26
本文介绍了Assetic 添加文件位于 app/Resources/js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个需要 3rd 方 js 文件的包.根据文档:

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

捆绑包不应包含第 3 方代码.由于该包仅用于站点的一部分,我不想将其包含在我的基本模板文件中 - 我想从 twig 文件中调用它,但我在那里遇到了问题.

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.

所有包含 js 的演示似乎都引用了一个包名称,但我已将我的 js 放在 app/Resources/public/js 中

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

如果我使用:

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

它在网络目录中查找.有没有办法使用我所有其他js文件所在的应用程序目录?我正在尝试在可行的情况下遵循最佳实践,但为了简单起见,我真的希望将我的 js 放在一个地方,感谢阅读!

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!

推荐答案

您可以通过符号链接 app/Resources 中的 Public 目录来实现.这有点乱,但它应该可以工作.

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

在 *nix 上,您可以运行:

On *nix, you could run:

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

基本上,您正在创建指向您的 Public 目录的 common 符号链接.

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

那么:

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

这篇关于Assetic 添加文件位于 app/Resources/js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆