Symfony2 Assetic wrong cssrewrite resources path in css/less files Symfony2 Assetic wrong cssrewrite resources path in css/less files symfony symfony

Symfony2 Assetic wrong cssrewrite resources path in css/less files


I had the same problem when specifying write_to option for assetic (suppose, I wanted my styles output into web/assets/css/styles.css):

assetic:    write_to:       '%kernel.root_dir%/../web/assets'    assets:        my_stylesheets:            output: 'css/styles.css'            inputs:                - 'bundles/mybundle/css/styles.css'

I could not find a better solution rather then not specifying anything else than web/ folder for write_to option (or not specifying it at all). However, you can still use subfolders for every separate asset:

assetic:    write_to:       '%kernel.root_dir%/../web'    assets:        my_stylesheets:            output: 'assets/css/styles.css'            inputs:                - 'bundles/mybundle/css/styles.css'

P.S. In both of upper cases styles will be in web/assets/css/styles.css, but in first case csrewrite will give incorrect paths, while the second one will work fine.


Your using the wrong type of definitions to your assets in your template, see the following ( note the @ prefix ). Also in your css you have to go relatively down from your Bundle/Resources/public/less folder. So it's not /bundles/ or ../bundles but most likely ../images/.

    {% stylesheets filter='less,cssembed,?yui_css' output='css/final.css'        '@AcmeDemoBundle/Resources/public/beautifulslider.css'        '@AcmeDemoBundle/Resources/public/less/site.less'    %}    <link href="{{ asset_url }}" type="text/css" rel="stylesheet" media="screen" />    {% endstylesheets %}

Update1

Given the above, one of my projects is in the same kind of setup, it's just still on 2.2 but i don't think that would matter, I just gave it a try removing these lines from my .less

    & > a {    background:transparent url('../images/btn-big-gray.png') repeat-x;    }

Images gone after

    xxx michael [master] $ app/console assetic:dump --env=dev

I restore the line and after kicking assetic again they're back... I think the dis recommendation doesn't count for the fact LESS is involved?


This is a common problem, I suggest you to not use cssrewrite filter and use urls with / at the beginning

url("/bundles/mybundle/images/colorfulbg.jpg");

Of course this approach has a drawback that website must be installed in a root directory for domain but to be honest I haven't seen Symfony project installed in sub directory.