vendor/twig/twig/src/Extension/StringLoaderExtension.php line 38

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Twig.
  4.  *
  5.  * (c) Fabien Potencier
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Twig\Extension;
  11. use Twig\Environment;
  12. use Twig\TemplateWrapper;
  13. use Twig\TwigFunction;
  14. final class StringLoaderExtension extends AbstractExtension
  15. {
  16.     public function getFunctions(): array
  17.     {
  18.         return [
  19.             new TwigFunction('template_from_string', [self::class, 'templateFromString'], ['needs_environment' => true]),
  20.         ];
  21.     }
  22.     /**
  23.      * Loads a template from a string.
  24.      *
  25.      *     {{ include(template_from_string("Hello {{ name }}")) }}
  26.      *
  27.      * @param string|null $name An optional name of the template to be used in error messages
  28.      *
  29.      * @internal
  30.      */
  31.     public static function templateFromString(Environment $envstring|\Stringable $template, ?string $name null): TemplateWrapper
  32.     {
  33.         return $env->createTemplate((string) $template$name);
  34.     }
  35. }