From c034c1d2489b43d0bab1b9a09d9b7e575a199d43 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 22 Sep 2022 00:58:09 +0200 Subject: [PATCH 1/2] Adding installation instructions for Symfony Wording is taken from https://twig.symfony.com/doc/3.x/filters/format_datetime.html --- doc/functions/template_from_string.rst | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/doc/functions/template_from_string.rst b/doc/functions/template_from_string.rst index d3f394e0ebe..d523f91aa9f 100644 --- a/doc/functions/template_from_string.rst +++ b/doc/functions/template_from_string.rst @@ -21,9 +21,18 @@ any related error message: .. note:: - The ``template_from_string`` function is not available by default. You - must add the ``\Twig\Extension\StringLoaderExtension`` extension explicitly when - creating your Twig environment:: + The ``template_from_string`` function is not available by default. + + In Symfony projects, you need to load it in your ``services.yaml``:: + + services: + Twig\Extension\StringLoaderExtension: + + or ``services.php``:: + + $services->set(\Twig\Extension\StringLoaderExtension::class); + + Otherwise, add the extension explicitly on the Twig environment:: $twig = new \Twig\Environment(...); $twig->addExtension(new \Twig\Extension\StringLoaderExtension()); From 9170edfa35493e557dcd1cae95a20d20402b8de2 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 28 Sep 2022 08:39:08 +0200 Subject: [PATCH 2/2] Fix doc CS --- doc/functions/template_from_string.rst | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/functions/template_from_string.rst b/doc/functions/template_from_string.rst index d523f91aa9f..ff6d271fd40 100644 --- a/doc/functions/template_from_string.rst +++ b/doc/functions/template_from_string.rst @@ -22,20 +22,24 @@ any related error message: .. note:: The ``template_from_string`` function is not available by default. - - In Symfony projects, you need to load it in your ``services.yaml``:: + + On Symfony projects, you need to load it in your ``services.yaml`` file: + + .. code-block:: yaml services: Twig\Extension\StringLoaderExtension: - or ``services.php``:: + or ``services.php`` file:: $services->set(\Twig\Extension\StringLoaderExtension::class); - + Otherwise, add the extension explicitly on the Twig environment:: + use Twig\Extension\StringLoaderExtension; + $twig = new \Twig\Environment(...); - $twig->addExtension(new \Twig\Extension\StringLoaderExtension()); + $twig->addExtension(new StringLoaderExtension()); .. note::