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 12namespace Twig\Extension { 13use Twig\TwigFunction; 14 15final class StringLoaderExtension extends AbstractExtension 16{ 17 public function getFunctions() 18 { 19 return [ 20 new TwigFunction('template_from_string', 'twig_template_from_string', ['needs_environment' => true]), 21 ]; 22 } 23} 24 25class_alias('Twig\Extension\StringLoaderExtension', 'Twig_Extension_StringLoader'); 26} 27 28namespace { 29use Twig\Environment; 30use Twig\TemplateWrapper; 31 32/** 33 * Loads a template from a string. 34 * 35 * {{ include(template_from_string("Hello {{ name }}")) }} 36 * 37 * @param string $template A template as a string or object implementing __toString() 38 * @param string $name An optional name of the template to be used in error messages 39 * 40 * @return TemplateWrapper 41 */ 42function twig_template_from_string(Environment $env, $template, string $name = null) 43{ 44 return $env->createTemplate((string) $template, $name); 45} 46} 47