问题描述
我试图了解symfony2资产捆绑包.我正在尝试使用一个jQuery插件,该插件使用它自己的css文件.我将所有内容都放在了mybundle/Resources/public
中,然后拆分为images/javascript/和css/
I'm trying to understand symfony2 assetic bundle.I'm trying to use a jquery plugin which uses it's own css file. I've put everything in mybundle/Resources/public
and then split into images/ javascript/ and css/
css插件正在使用相对路径来获取类似../images/sprite.png
The plugins css is using relative paths to get the images like ../images/sprite.png
使用资产来提供css文件:
Using assetic to serve the css file:
{% stylesheets
'@MyBundle/Resources/public/css/mycss.css'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
assetic生成的路径是/app_dev.php/css/mycss.css
,我猜这是正确的.显然,相对图像路径现在不再起作用.因为文件本身位于mybundle/Resources/public中,而不位于/images/
The path generated by assetic is /app_dev.php/css/mycss.css
, which is correct i guess. Obviously the relative image pathes are not working anymore now. Because the files itself are located in mybundle/Resources/public and not in /images/
当尝试使用cssrewrite过滤器时,路径将被重写为:http://server.com/Resources/public/images/sprite.png
.但这不正确,文件不在此处.
When trying to use the cssrewrite filter, the pathes are rewritten to:http://server.com/Resources/public/images/sprite.png
. But this i not correct, the files are not located there.
我如何使用Assetic服务相对的图像?
How can i serve the images relative using assetic?
推荐答案
您可以拼出输出路径,而根本不使用cssrewrite.
You can spell out the output path and not use cssrewrite at all.
{% stylesheets output="bundles/zaysoarbiter/css/forms2.css"
'@ZaysoArbiterBundle/Resources/public/css/forms2.css'
%}
然后当然可以使用assets:install
将图像复制到web/bundles/bundle/images
或任何位置.就浏览器而言,您的CSS和图像现在彼此相对放置.在生产中,您将使用assetic:dump
将实际生成的css文件移到上方.
And then of course you use assets:install
to copy your images to web/bundles/bundle/images
or wherever. As far as the browser is concerned, your css and images are now located relative to each other. In production you will use assetic:dump
to move the actual generated css file over.
这篇关于使用资源提供相对图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!