Serving relative images using assetic

爱⌒轻易说出口 提交于 2019-12-06 03:36:31

问题


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/

The plugins css is using relative paths to get the images like ../images/sprite.png

Using assetic to serve the css file:

{% stylesheets
    '@MyBundle/Resources/public/css/mycss.css' 
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}

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/

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.

How can i serve the images relative using assetic?


回答1:


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'
%}

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.



来源:https://stackoverflow.com/questions/9501248/serving-relative-images-using-assetic

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