1``template_from_string``
2========================
3
4.. versionadded:: 2.8
5
6    The name argument was added in Twig 2.8.
7
8The ``template_from_string`` function loads a template from a string:
9
10.. code-block:: twig
11
12    {{ include(template_from_string("Hello {{ name }}")) }}
13    {{ include(template_from_string(page.template)) }}
14
15To ease debugging, you can also give the template a name that will be part of
16any related error message:
17
18.. code-block:: twig
19
20    {{ include(template_from_string(page.template, "template for page " ~ page.name)) }}
21
22.. note::
23
24    The ``template_from_string`` function is not available by default. You
25    must add the ``\Twig\Extension\StringLoaderExtension`` extension explicitly when
26    creating your Twig environment::
27
28        $twig = new \Twig\Environment(...);
29        $twig->addExtension(new \Twig\Extension\StringLoaderExtension());
30
31.. note::
32
33    Even if you will probably always use the ``template_from_string`` function
34    with the ``include`` function, you can use it with any tag or function that
35    takes a template as an argument (like the ``embed`` or ``extends`` tags).
36
37Arguments
38---------
39
40* ``template``: The template
41* ``name``: A name for the template
42