I want to put a background image for a menu in symfony. But I can't figure out how to do it.
I managed to style a lot of things already, but not to add a background from css.
This is my project src
folder with the background style that I am trying to create:
What is the correct path for Symfony to know where is the image? I have tried multiple things and nothing works for me. THX
You should store your images in the bundle folder.
src/MyBundle/Resources/public/images
and your css in
src/MyBundle/Resources/public/css
since only web folder is accesible from outside you should use the command
app/console assets:install web --symlink
this will now create the links for the web folder as
web/bundles/Project_name/css
web/bundles/Project_name/images
So your relative path for the image would be as
.header{
background-image: url("../images/mainlogo.gif");
}
And in twig you should use asset() function to link your styles:
<link href="{{ asset('bundles/acmeweb/css/yourstylesheet.css') }}" rel="stylesheet" type="text/css" />
you can find complete documentation here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With