1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-12-22 20:35:54 +01:00
vichan/inc/lib/Twig/Extension/StringLoader.php

48 lines
1.1 KiB
PHP
Raw Normal View History

2013-08-01 21:20:12 +02:00
<?php
/*
* This file is part of Twig.
*
2018-05-10 12:24:53 +02:00
* (c) Fabien Potencier
2013-08-01 21:20:12 +02:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2018-05-10 12:24:53 +02:00
/**
* @final
*/
2013-08-01 21:20:12 +02:00
class Twig_Extension_StringLoader extends Twig_Extension
{
public function getFunctions()
{
return array(
new Twig_SimpleFunction('template_from_string', 'twig_template_from_string', array('needs_environment' => true)),
);
}
public function getName()
{
return 'string_loader';
}
}
/**
* Loads a template from a string.
*
* <pre>
* {{ include(template_from_string("Hello {{ name }}")) }}
* </pre>
*
* @param Twig_Environment $env A Twig_Environment instance
2018-05-10 12:24:53 +02:00
* @param string $template A template as a string or object implementing __toString()
2013-08-01 21:20:12 +02:00
*
2018-05-10 12:24:53 +02:00
* @return Twig_Template
2013-08-01 21:20:12 +02:00
*/
function twig_template_from_string(Twig_Environment $env, $template)
{
2018-05-10 12:24:53 +02:00
return $env->createTemplate((string) $template);
2013-08-01 21:20:12 +02:00
}
2018-05-10 12:24:53 +02:00
class_alias('Twig_Extension_StringLoader', 'Twig\Extension\StringLoaderExtension', false);