This question already has an answer here:
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 ?
</div>
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 css rewrite filter can solve this situation:
{% stylesheets "css/bootstrap.css" filter="cssrewrite" %}
<link rel="stylesheet" type="text/css" href="{{ asset_url }}" />
{% endstylesheets %}
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