Skip to content
CSS inliner support for Twig
Branch: master
Clone or download
fabpot minor #1 Fix the Twig constraint lowest bounds (stof)
This PR was merged into the 2.0-dev branch.


Fix the Twig constraint lowest bounds

This extension relies on namespaced classes.


ff0e080 Fix the Twig constraint lowest bounds
Latest commit 295cc11 Feb 26, 2019

Twig CSS Inliner Extension

This package provides a CSS inliner filter (inline_css) for Twig and a Symfony bundle.

If you are not using Symfony, register the extension on Twig's Environment manually:

use Twig\CssInliner\CssInlinerExtension;
use Twig\Environment;

$twig = new Environment(...);
$twig->addExtension(new CssInlinerExtension());

Use the inline_css filter from a Twig template:

{% filter inline_css %}
                p { color: red; }
            <p>Hello CSS!</p>
{% endfilter %}

You can also add some stylesheets by passing them as arguments to the filter:

{% filter inline_css(source("some_styles.css"), source("another.css")) %}
            <p>Hello CSS!</p>
{% endfilter %}

Styles loaded via the filter override the styles defined in the <style> tag of the HTML document.

You can also use the filter on an included file:

{{ include('some_template.html.twig')|inline_css }}

{{ include('some_template.html.twig')|inline_css(source("some_styles.css")) }}

Note that the CSS inliner works on an entire HTML document, not a fragment.

You can’t perform that action at this time.