Path of assets in CSS files in Symfony 2
One common task when working with Symfony2 is to reference CSS or image files from a CSS file. This can be challenging due to the way Symfony2 manages its assets.
One approach is to use the assetic:dump command. This command compiles different asset files into a single file. In this case, it recompiles CSS files and rewrites the paths to the images.
Unfortunately, this approach has limitations. For example, if the CSS file is in a subdirectory, the assetic:dump command may not generate the correct path to the image.
Another approach is to have a separate CSS file with only relative paths to the images and to have the path to CSS file from Resources/assets instead of Resources/public. This will work even if the CSS file is in a subdirectory and the correct path to image will be generated as it doesn't depend on the path of the CSS file.
The above is the detailed content of ## How to correctly reference images from CSS files in Symfony2?. For more information, please follow other related articles on the PHP Chinese website!