The background image does not display after importing css in the symfony2 front-end template
我想大声告诉你
我想大声告诉你 2017-05-16 16:44:10
0
2
573

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!

我想大声告诉你
我想大声告诉你

reply all (2)
淡淡烟草味

If you are using Assetic, then you need to add cssrewrite filer, that is:

{% stylesheets 'bundles/app/css/*' filter='cssrewrite' %}

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:

/src/AppBundle/Resources/public/img/logo.png /src/AppBundle/Resources/public/css/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:

/web/bundles/app/img/logo.png /web/css/11e4a17.css

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

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!