<commit_before>``include``
===========

The ``include`` statement includes a template and outputs the rendered content
of that file:

.. code-block:: twig

    {% include 'header.html' %}
        Body
    {% include 'footer.html' %}

.. note::

    As of Twig 1.12, it is recommended to use the
    :doc:`include<../functions/include>` function instead as it provides the
    same features with a bit more flexibility:

    * The ``include`` function is semantically more "correct" (including a
      template outputs its rendered contents in the current scope; a tag should
      not display anything);

    * The ``include`` function is more "composable":

      .. code-block:: twig

          {# Store a rendered template in a variable #}
          {% set content %}
              {% include 'template.html' %}
          {% endset %}
          {# vs #}
          {% set content = include('template.html') %}

          {# Filter a rendered template #}
          {% filter upper %}
              {% include 'template.html' %}
          {% endfilter %}
          {# vs #}
          {{ include('template.html')|upper }}

    * The ``include`` function does not impose any specific order for
      arguments thanks to :ref:`named arguments <named-arguments>`.

Included templates have access to the variables of the active context.

If you are using the filesystem loader, the templates are looked for in the
paths defined by it.

You can add additional variables by passing them after the ``with`` keyword:

.. code-block:: twig

    {# template.html will have access to the variables from the current context and the additional ones provided #}
    {% include 'template.html' with {'foo': 'bar'} %}

    {% set vars = {'foo': 'bar'} %}
    {% include 'template.html' with vars %}

You can disable access to the context by appending the ``only`` keyword:

.. code-block:: twig

    {# only the foo variable will be accessible #}
    {% include 'template.html' with {'foo': 'bar'} only %}<commit_msg>Fix include documentation - change filter tag to apply<commit_after>``include``
===========

The ``include`` statement includes a template and outputs the rendered content
of that file:

.. code-block:: twig

    {% include 'header.html' %}
        Body
    {% include 'footer.html' %}

.. note::

    As of Twig 1.12, it is recommended to use the
    :doc:`include<../functions/include>` function instead as it provides the
    same features with a bit more flexibility:

    * The ``include`` function is semantically more "correct" (including a
      template outputs its rendered contents in the current scope; a tag should
      not display anything);

    * The ``include`` function is more "composable":

      .. code-block:: twig

          {# Store a rendered template in a variable #}
          {% set content %}
              {% include 'template.html' %}
          {% endset %}
          {# vs #}
          {% set content = include('template.html') %}

          {# Apply filter on a rendered template #}
          {% apply upper %}
              {% include 'template.html' %}
          {% endapply %}
          {# vs #}
          {{ include('template.html')|upper }}

    * The ``include`` function does not impose any specific order for
      arguments thanks to :ref:`named arguments <named-arguments>`.

Included templates have access to the variables of the active context.

If you are using the filesystem loader, the templates are looked for in the
paths defined by it.

You can add additional variables by passing them after the ``with`` keyword:

.. code-block:: twig

    {# template.html will have access to the variables from the current context and the additional ones provided #}
    {% include 'template.html' with {'foo': 'bar'} %}

    {% set vars = {'foo': 'bar'} %}
    {% include 'template.html' with vars %}

You can disable access to the context by appending the ``only`` keyword:

.. code-block:: twig

    {# only the foo variable will be accessible #}
    {% include 'template.html' with {'foo': 'bar'} only %}
{'fraction_non_alphanumeric': 0.11931818181818182, 'fraction_numerical': 0.0014822134387351778, 'mean_word_length': 2.707875457875458, 'pattern_counts': {'":': 2, '<': 7, '<?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': '3177061', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1012, 'n_words': 451}