<commit_before>``template_from_string``
========================

.. versionadded:: 2.8

    The name argument was added in Twig 2.8.

The ``template_from_string`` function loads a template from a string:

.. code-block:: twig

    {{ include(template_from_string("Hello {{ name }}")) }}
    {{ include(template_from_string(page.template)) }}

To ease debugging, you can also give the template a name that will be part of
any related error message:

.. code-block:: twig

    {{ include(template_from_string(page.template, "template for page " ~ page.name)) }}

.. note::

    The ``template_from_string`` function is not available by default.
    
    In Symfony projects, you need to load it in your ``services.yaml``::

        services:
            Twig\Extension\StringLoaderExtension:

    or ``services.php``::

        $services->set(\Twig\Extension\StringLoaderExtension::class);
    
    Otherwise, add the extension explicitly on the Twig environment::

        $twig = new \Twig\Environment(...);
        $twig->addExtension(new \Twig\Extension\StringLoaderExtension());

.. note::

    Even if you will probably always use the ``template_from_string`` function
    with the ``include`` function, you can use it with any tag or function that
    takes a template as an argument (like the ``embed`` or ``extends`` tags).

Arguments
---------

* ``template``: The template
* ``name``: A name for the template
<commit_msg>Fix doc CS<commit_after>``template_from_string``
========================

.. versionadded:: 2.8

    The name argument was added in Twig 2.8.

The ``template_from_string`` function loads a template from a string:

.. code-block:: twig

    {{ include(template_from_string("Hello {{ name }}")) }}
    {{ include(template_from_string(page.template)) }}

To ease debugging, you can also give the template a name that will be part of
any related error message:

.. code-block:: twig

    {{ include(template_from_string(page.template, "template for page " ~ page.name)) }}

.. note::

    The ``template_from_string`` function is not available by default.

    On Symfony projects, you need to load it in your ``services.yaml`` file:

    .. code-block:: yaml

        services:
            Twig\Extension\StringLoaderExtension:

    or ``services.php`` file::

        $services->set(\Twig\Extension\StringLoaderExtension::class);

    Otherwise, add the extension explicitly on the Twig environment::

        use Twig\Extension\StringLoaderExtension;

        $twig = new \Twig\Environment(...);
        $twig->addExtension(new StringLoaderExtension());

.. note::

    Even if you will probably always use the ``template_from_string`` function
    with the ``include`` function, you can use it with any tag or function that
    takes a template as an argument (like the ``embed`` or ``extends`` tags).

Arguments
---------

* ``template``: The template
* ``name``: A name for the template

{'fraction_non_alphanumeric': 0.13830879835672716, 'fraction_numerical': 0.0027387880862718246, 'mean_word_length': 3.440729483282675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2749959', 'n_tokens_mistral': 818, 'n_tokens_neox': 788, 'n_words': 284}