Skip to content

Commit 0277ded

Browse files
committed
minor symfony#17633 [Mailer] Add html_to_text_converter config docs (fabpot)
This PR was merged into the 6.2 branch. Discussion ---------- [Mailer] Add html_to_text_converter config docs Closes symfony#17262 Commits ------- d937f04 Add html_to_text_converter config docs
2 parents 2bbd8df + d937f04 commit 0277ded

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

mailer.rst

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -717,12 +717,22 @@ method of the ``TemplatedEmail`` class and also to a special variable called
717717
Text Content
718718
~~~~~~~~~~~~
719719

720-
When the text content of a ``TemplatedEmail`` is not explicitly defined, mailer
721-
will generate it automatically by converting the HTML contents into text. If you
722-
have `league/html-to-markdown`_ installed in your application,
723-
it uses that to turn HTML into Markdown (so the text email has some visual appeal).
724-
Otherwise, it applies the :phpfunction:`strip_tags` PHP function to the original
725-
HTML contents.
720+
When the text content of a ``TemplatedEmail`` is not explicitly defined, it is
721+
automatically generated from the HTML contents.
722+
723+
Symfony uses the following strategy when generating the text version of an
724+
email:
725+
726+
* If an explicit HTML to text converter has been configured (see
727+
:ref:`twig.mailer.html_to_text_converter
728+
<config-twig-html-to-text-converter>`), it calls it;
729+
730+
* If not, and if you have `league/html-to-markdown`_ installed in your
731+
application, it uses it to turn HTML into Markdown (so the text email has
732+
some visual appeal);
733+
734+
* Otherwise, it applies the :phpfunction:`strip_tags` PHP function to the
735+
original HTML contents.
726736

727737
If you want to define the text content yourself, use the ``text()`` method
728738
explained in the previous sections or the ``textTemplate()`` method provided by
@@ -732,13 +742,13 @@ the ``TemplatedEmail`` class:
732742
733743
+ use Symfony\Bridge\Twig\Mime\TemplatedEmail;
734744
735-
$email = (new TemplatedEmail())
736-
// ...
745+
$email = (new TemplatedEmail())
746+
// ...
737747
738-
->htmlTemplate('emails/signup.html.twig')
748+
->htmlTemplate('emails/signup.html.twig')
739749
+ ->textTemplate('emails/signup.txt.twig')
740-
// ...
741-
;
750+
// ...
751+
;
742752
743753
.. _mailer-twig-embedding-images:
744754

reference/configuration/twig.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,25 @@ globals
302302
It defines the global variables injected automatically into all Twig templates.
303303
Learn more about :doc:`Twig global variables </templating/global_variables>`.
304304

305+
mailer
306+
~~~~~~
307+
308+
.. _config-twig-html-to-text-converter:
309+
310+
html_to_text_converter
311+
......................
312+
313+
**type**: ``string`` **default**: ````
314+
315+
.. versionadded:: 6.2
316+
317+
The ``html_to_text_converter`` option was introduced in Symfony 6.2.
318+
319+
The service implementing
320+
:class:`Symfony\\Component\\Mime\\HtmlToTextConverter\\HtmlToTextConverterInterface`
321+
that will be used to automatically create the text part of an email from its
322+
HTML contents when not explicitely defined.
323+
305324
number_format
306325
~~~~~~~~~~~~~
307326

0 commit comments

Comments
 (0)