Css/image problem in symfony template

in my app/Resources/views/base.html.php I have this:

<link href="<?php echo $view['assets']->getUrl('src/Application/AdminBundle/Resources/public/css/style.css') ?>" rel="stylesheet" type="text/css" />

and in source I get this:

<link href="/symfony/src/Application/AdminBundle/Resources/public/css/style.css" rel="stylesheet" type="text/css" />

probably I have to add that I moved my app.php from web to my root, and /symphony/ is the root folder. so it is something wrong. and if I change it to:

<link href="src/Application/AdminBundle/Resources/public/css/style.css" rel="stylesheet" type="text/css" />

again this is wrong because of query params in URI. so how to fix it?

in twig template I use this for image:

{% image '@AcmeFooBundle/Resources/public/images/example.jpg' %}
    <img src="{{ asset_url }}" alt="Example" />
{% endimage %}

and this for css:

{% stylesheets '@AppBundle/Resources/public/css/*' %}
   <link rel="stylesheet" href="{{ asset_url }}" type="text/css" />
{% endstylesheets %}

But in my css I have some classes with image:

background-image: url(../images/left_menu_bg.jpg);

Of course the image is broken, Is there any way to solve this? or I need to move the background image to twig template any way? if yes how can I have a background imgae for div?

<div class="blah" background="image.jpg">

I did run
assets:install and use cssrewrite filter in css tag. Css file itself is loaded from /bundles/mybundles/css but the images in css is still broken even with adding filter=‘cssrewrite’ in css tag. How the path in css file should be to load images from /bundles/mybundle/images?

as css file is located at /web/bundles/appbundle/css/style.css I guess for background image I should have a relative path to reach outside of /web/ folder like this?

background-image: url(../../../../bundles/appbundle/images/top_bg.jpg);

but it doesn’t work yet, I have filter=‘cssrewrite’ in css tag tag too. please advice. probably I have to add that I am only editing the css file located at the path above after assets install, I did not edit the one in /Acme/Bundle/Resources/public/css.

when I have: {% stylesheets ‘bundles/appbundle/css/*’ filter=‘cssrewrite’ %}
the image path in /bundles/appbundle/css/style.php
is just …/images/top_bg.jpg
then the link becomes
https://www.mysite.com/bundles/appbundle/images/top_bg.jpg 404 (Not Found)

but after dumping assets when I change it to:
{% stylesheets ‘css/*’ filter=‘cssrewrite’ %}
the link becomes
https://www.mysite.com/symfony/bundles/appbundle/images/top_bg.jpg 404 (Not Found)
and the path in /css/xxxxstyle.css is:
…/…/bundles/appbundle/images/top_bg.jpg

but the image is actually in:
h t t p s ://www.mysite.com/symfony/web/bundles/appbundle/images/top_bg.jpg

I don’t think pointing the twig to ‘css/*’ is good idea for me, because I have two User and Admin bundle,

and each area has a separate css file.

what should I do?
PS. found this too.

I apologies for everything here! I discovered the issue. please see this post

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.