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