Run CSS file through Twig when using {% stylesheets %} tag in Twig with Symfony2

Not Available picture Not Available · Jun 14, 2012 · Viewed 19.1k times · Source

I'm including CSS stylesheets in my template like so:

{% stylesheets
    "@SomeBundle/Resources/assets/css/default.css.twig"
    "@SomeBundle/Resources/assets/css/global.css.twig"
%}
    <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}

However I want to run these CSS files through Twig, is this in any way possible while using the {% stylesheets %} tag or does this require some other approach. I've already tried enabling a twig filter but that does not exist.

Answer

Pappa picture Pappa · Jun 14, 2012

You could do it if you load the css as an internal stylesheet. Something like this:

{% block stylesheets %}
    {{ parent() }}
    {% include 'AcmeBundle:Bundle:mycss.css.twig' %}
{% endblock %}

And then the mycss.css.twig template would contain:

<style type="text/css">
    /* */
</style>