1
votes

I'm using kriswallsmith assetic bundle to serve css with compass filter, in dev environment is generated each time and in prod environment styles are served with the dumped css files with no compass action. So I'm wondering if there is a way in dev env to serve the same css files than prod env if smyfony is not be able to find compass binary.

Here is how I load the sass files in my head:

{% stylesheets filter="compass"
    "@Bundle/Resources/public/css/colors.sass"
    "@Bundle/Resources/public/css/layout.sass"
    "@Bundle/Resources/public/css/menu.sass"
    "@Bundle/Resources/public/css/main.sass"
    "@Bundle/Resources/public/css/fonts.sass"
%}
    <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}

Is there a workaround for this?

1
please review my asnwer - was that what you expected?Nicolai Fröhlich

1 Answers

1
votes

You can use the question mark (?) in front of a filter to apply it only in production mode or more precise when debug mode is off.

{% stylesheets filter="?compass"
    "@Bundle/Resources/public/css/colors.sass"
     // ...
%}
     <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %} 

you can also set the debug option to false for this asset collection which will prevent assetic from creating single files ( for easier debugging ) if you use assetic:dump without the --no-debug option.

Assetic will then only concatenate the files which will work for .sass files as long as you have included a JavaScript based compiler included in your html in dev environment.

{% stylesheets filter="?compass" debug="false"
    "@Bundle/Resources/public/css/colors.sass"
     // ...
%}
     <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %} 

The second option is to include a static file in dev enviroment. Therefore add a twig global in config.yml under twig section set to your current kernel.environment parameter.

# app/config/config.yml

twig:
    globals:
        env: %kernel.environment%

and then use it in twig like this:

{% if env == 'dev' %}
    <link rel="stylesheet" href="{{ asset('/path/to/your/compiled/asset.css"') }} />
{% else }
    // ...
 {% endif %}

The asset() helper will make sure your asset is output correctly even if you are using app_dev.php in your url.