From d937f048474fd9b7f8747250fb4b5770426fb24a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 30 Dec 2022 08:53:16 +0100 Subject: [PATCH] Add html_to_text_converter config docs --- mailer.rst | 32 +++++++++++++++++++++----------- reference/configuration/twig.rst | 19 +++++++++++++++++++ 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/mailer.rst b/mailer.rst index a1d2577def5..7c8ab512493 100644 --- a/mailer.rst +++ b/mailer.rst @@ -717,12 +717,22 @@ method of the ``TemplatedEmail`` class and also to a special variable called Text Content ~~~~~~~~~~~~ -When the text content of a ``TemplatedEmail`` is not explicitly defined, mailer -will generate it automatically by converting the HTML contents into text. If you -have `league/html-to-markdown`_ installed in your application, -it uses that to turn HTML into Markdown (so the text email has some visual appeal). -Otherwise, it applies the :phpfunction:`strip_tags` PHP function to the original -HTML contents. +When the text content of a ``TemplatedEmail`` is not explicitly defined, it is +automatically generated from the HTML contents. + +Symfony uses the following strategy when generating the text version of an +email: + +* If an explicit HTML to text converter has been configured (see + :ref:`twig.mailer.html_to_text_converter + `), it calls it; + +* If not, and if you have `league/html-to-markdown`_ installed in your + application, it uses it to turn HTML into Markdown (so the text email has + some visual appeal); + +* Otherwise, it applies the :phpfunction:`strip_tags` PHP function to the + original HTML contents. If you want to define the text content yourself, use the ``text()`` method explained in the previous sections or the ``textTemplate()`` method provided by @@ -732,13 +742,13 @@ the ``TemplatedEmail`` class: + use Symfony\Bridge\Twig\Mime\TemplatedEmail; - $email = (new TemplatedEmail()) - // ... + $email = (new TemplatedEmail()) + // ... - ->htmlTemplate('emails/signup.html.twig') + ->htmlTemplate('emails/signup.html.twig') + ->textTemplate('emails/signup.txt.twig') - // ... - ; + // ... + ; .. _mailer-twig-embedding-images: diff --git a/reference/configuration/twig.rst b/reference/configuration/twig.rst index 54961707833..ce6dd45a772 100644 --- a/reference/configuration/twig.rst +++ b/reference/configuration/twig.rst @@ -302,6 +302,25 @@ globals It defines the global variables injected automatically into all Twig templates. Learn more about :doc:`Twig global variables `. +mailer +~~~~~~ + +.. _config-twig-html-to-text-converter: + +html_to_text_converter +...................... + +**type**: ``string`` **default**: ```` + +.. versionadded:: 6.2 + + The ``html_to_text_converter`` option was introduced in Symfony 6.2. + +The service implementing +:class:`Symfony\\Component\\Mime\\HtmlToTextConverter\\HtmlToTextConverterInterface` +that will be used to automatically create the text part of an email from its +HTML contents when not explicitely defined. + number_format ~~~~~~~~~~~~~ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy