Based on work by Roberto Trunfio on https://github.com/robertotru/ToInlineStyleEmailBundle
Makes use of https://github.com/tijsverkoyen/CssToInlineStyles by Tijs Verkoyen
This twig extension is installed through Composer. Run the following command from the root of your project:
composer require nerds-and-company/css-to-inline-styles-twig-extension
This will add nerds-and-company/css-to-inline-styles-twig-extension as a requirement to your project's composer.json file and install the source-code into the vendor/nerds-and-company/css-to-inline-styles-twig-extension directory
Add the extension to the Twig_Environment
:
use NerdsAndCompany\CssToInlineStyles\Twig\InlineCssExtension;
use Twig\Environment;
$twig = new Environment(...);
$twig->addExtension(new InlineCssExtension());
{% inlinecss '/absolute/path/file.css' %}
<tag>Html to be converted</tag>
{% endinlinecss %}