0

I'm a newbie to both php and symfony. I have been using successfully the following syntax for including css and scripts to my page:

<link rel="stylesheet" type="text/css" href="{{ asset('css/bootstrap.css') }}">

Now, I have a css that refers to an image

.menu{
 background: url(../img/mobile.png) no-repeat center;
}

The image is not found. I think this is because I cannot use the asset() syntax here.

How can I solve this problem ?

2
  • Where exactly do you use the asset()? Can you post that code? Commented Aug 1, 2013 at 16:37
  • yes sorry, I've edited my post.But the question is how do I do that in a css file. Commented Aug 1, 2013 at 16:39

3 Answers 3

0

look at the web folder and if the image exist or not because you don't use asset in css just in twig

did you generate the images with assets:install web so that the images exist in the web folder

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

2 Comments

the image is in the web/img folder. I did not generate anything (I don't even know what assets:install is. I just dropped the img folder into the web folder. Should that not be enough ?
no it's not because the img folder sould be in \web\bundles\nameofyourbundle exemple \web\bundles\AcmeExemple
0

The css rewrite filter can solve this situation:

{% stylesheets "css/bootstrap.css" filter="cssrewrite" %}
    <link rel="stylesheet" type="text/css" href="{{ asset_url }}" />
{% endstylesheets %}

Comments

0

Simply try this:

<link rel="stylesheet" type="text/css" href="{{ asset('bundles/YOUR_BUNDLE_NAME/css/bootstrap.css') }}">

Where YOUR_BUNDLE_NAME is ex. testbundle

Make sure you put bootstrap.css file into /TestBundle/Resources/public/css directory.

Execute command:

php app/console assets:install 

This command will 'hard copy' all files in public folder to web folder where it will be available.

Your path to css fiels will be now bundles/testbundle/css/bootstrap.css

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.