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 ?

Sam
  • 13,934
  • 26
  • 108
  • 194

3 Answers3

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

  • 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 ? – Sam Aug 01 '13 at 16:46
  • no it's not because the img folder sould be in \web\bundles\nameofyourbundle exemple \web\bundles\AcmeExemple – Sofien Benrhouma Aug 01 '13 at 21:11
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 %}
Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130
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

takeit
  • 3,991
  • 1
  • 20
  • 36