Project

General

Profile

1
<?php
2

    
3
/*
4
 * This file is part of Twig.
5
 *
6
 * (c) 2012 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
class Twig_Extension_StringLoader extends Twig_Extension
12
{
13
    public function getFunctions()
14
    {
15
        return array(
16
            new Twig_SimpleFunction('template_from_string', 'twig_template_from_string', array('needs_environment' => true)),
17
        );
18
    }
19

    
20
    public function getName()
21
    {
22
        return 'string_loader';
23
    }
24
}
25

    
26
/**
27
 * Loads a template from a string.
28
 *
29
 * <pre>
30
 * {{ include(template_from_string("Hello {{ name }}")) }}
31
 * </pre>
32
 *
33
 * @param Twig_Environment $env      A Twig_Environment instance
34
 * @param string           $template A template as a string or object implementing __toString()
35
 *
36
 * @return Twig_Template A Twig_Template instance
37
 */
38
function twig_template_from_string(Twig_Environment $env, $template)
39
{
40
    return $env->createTemplate((string) $template);
41
}
(10-10/10)