After symfony2 manages the css, there is a background image defined in the css. Symfony2 changes the path of the css, but does not change the path of the background image defined in the css. As a result, the background image cannot be displayed. What should I do? Thank you in advance!
If you are using Assetic, then you need to add cssrewrite filer, that is:
What does this filter mean?
When you assets:dump (or assets:install), Symfony2 will move your static files (CSS) from the Bundle to the Web root directory, so the paths of some files have changed (such as those referenced in css image), thus causing the problem stated by the subject.
So the cssrewrite filter is specifically used to calculate the relative relationship between css and images, and directly update the path in CSS.
Let me give you a practical example. You now have two files logo.png and style.css:
You need ../img/logo.png to reference logo.png in style.css, right?
Now, when you assets:dump, the Assetic component of Symfony2 will export logo.png and style.css to the /web directory, because /src is not directly accessible, now logo.png and style.css will be Export in new directory:
You will see that the relative relationship between 11e4a17.css (the file after style.css was renamed) and logo.png has changed. The original ../img/logo.png can no longer reference logo.png. , the meaning of cssrewrite is that it will update ../img/logo.png in 11e4a17.css (style.css) to ../bundles/app/img/logo.png.
It’s so long-winded to say so much, I hope it can help the questioner.
You may not have read the document, I’ll give it to you
How to Use Assetic for Asset Management