2
votes

I have a problem using assetic and the cssrewrite filter using named assets. I have defined a named asset in the assets.yml like this:

assetic:
  assets:
    mycssfiles:
      inputs:
        - 'bundles/mybundle/css/mystyles.css'

In my twig template I use this asset with the cssrewrite filter:

{% stylesheets '@mycssfiles' output='css/styles.css' filter="cssrewrite" %}
    <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}

Using this config the result of the css has an incorrect url for the images included in the css file. But if I don't use the named asset it works correctly and the url for the images are rewrited correctly. This code works fine:

{% stylesheets 'bundles/mybundle/css/mystyles.css' output='css/styles.css' filter="cssrewrite" %}
    <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}

Does the cssrewrite filter not work with named assets? I know that it doesn't work with the @AppBundle sintax but I don't know if it doesn't work with named assets or I'm doing something wrong.

1
This is just a guess and I have no confirmation, but apparently the "@" syntax is what causes the issues with cssrewrite. - jahller
I know the cssrewrite doesn't work with the @AppBundle like here explain, but don't say anything about named assets - Carlos Mayo

1 Answers

3
votes

I post my conf for fontawesome, i hope this is helpful :) :

# Assetic Configuration
assetic:
    debug: "%kernel.debug%"
    use_controller: false
    bundles :       [AppBundle]
    java: /usr/bin/java
    filters:
        cssrewrite: ~
    assets:
    font_awesome:
        inputs:
            - "bundles/app/bower_components/components-font-awesome/css/font-awesome.min.css"
        filters:
            - cssrewrite

Twig part

    {% stylesheets filter='cssrewrite'
            '@font_awesome'
    %}
    <link rel="stylesheet" href="{{ asset_url }}" type="text/css" media="all"/>
    {% endstylesheets %}