5

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: Project structure

What is the correct path for Symfony to know where is the image? I have tried multiple things and nothing works for me. THX

1 Answer 1

15

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, app/console assets:install web --symlink this was exactly what I needed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.