From 486e9c13d6d2943dcd14f77c5e48ebf9433e326a Mon Sep 17 00:00:00 2001 From: Stefan Mainz Date: Sat, 1 Mar 2025 15:42:32 +0100 Subject: [PATCH 1/2] Inline CSS styles, so mailers can display the mail properly Uses symfony css inliner: https://symfony.com/doc/current/mailer.html#inlining-css-styles --- composer.json | 5 ++++- src/Factory/TwigFactory.php | 2 ++ templates/_base.html.twig | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2d27aa6..f0e4138 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,9 @@ "require": { "symfony/mailer": "^7.0", "twig/twig": "^3.8", - "symfony/google-mailer": "^7.1" + "symfony/google-mailer": "^7.1", + "symfony/process": "^7.2", + "twig/extra-bundle": "^3.20", + "twig/cssinliner-extra": "^3.20" } } diff --git a/src/Factory/TwigFactory.php b/src/Factory/TwigFactory.php index 7d176b2..74b487b 100644 --- a/src/Factory/TwigFactory.php +++ b/src/Factory/TwigFactory.php @@ -5,6 +5,7 @@ namespace Plugin\Factory; use Twig\Environment; use Twig\Extension\DebugExtension; use Twig\Extension\StringLoaderExtension; +use Twig\Extra\CssInliner\CssInlinerExtension; use Twig\Loader\FilesystemLoader; class TwigFactory @@ -16,6 +17,7 @@ class TwigFactory $twig = new Environment($loader); $twig->addExtension(new StringLoaderExtension()); $twig->addExtension(new DebugExtension()); + $twig->addExtension(new CssInlinerExtension()); return $twig; } diff --git a/templates/_base.html.twig b/templates/_base.html.twig index fb803c5..52d799c 100644 --- a/templates/_base.html.twig +++ b/templates/_base.html.twig @@ -1,4 +1,5 @@ +{% apply inline_css %} @@ -207,3 +208,4 @@ {% endblock %} +{% endapply %} -- 2.47.3 From 7360be6207a4468a2ebffd10981bc9673c8928ce Mon Sep 17 00:00:00 2001 From: Stefan Mainz Date: Sun, 2 Mar 2025 11:44:47 +0100 Subject: [PATCH 2/2] Remove symfony/process from dependencies --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index f0e4138..636f15f 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,6 @@ "symfony/mailer": "^7.0", "twig/twig": "^3.8", "symfony/google-mailer": "^7.1", - "symfony/process": "^7.2", "twig/extra-bundle": "^3.20", "twig/cssinliner-extra": "^3.20" } -- 2.47.3