Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
358 changes: 358 additions & 0 deletions reference/twig_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@
in the function name, e.g. ``render_hinclude()`` will use the hinclude.js
strategy. This works for all ``render_*()`` functions.

.. _reference-twig-function-render-ssi:

render_ssi
~~~~~~~~~~

.. code-block:: twig

{{ render_ssi(uri, options = []) }}

``uri``
**type**: ``string`` | ``ControllerReference``
``options`` *(optional)*
**type**: ``array`` **default**: ``[]``

It's similar to the `render`_ function and defines the same arguments. However,
it generates an SSI tag when :doc:`SSI support </http_cache/ssi>` is enabled or
falls back to the behavior of `render`_ otherwise.

fragment_uri
~~~~~~~~~~~~

Expand Down Expand Up @@ -528,6 +546,321 @@
Outputs the ``importmap`` & a few other items when using
:doc:`the Asset component </frontend/asset_mapper>`.

.. _reference-twig-function-dump:

dump
~~~~

.. code-block:: twig

{{ dump(var1, var2, ...) }}

Check failure on line 556 in reference/twig_reference.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Twig] Unexpected token "punctuation" of value ")".

Dumps information about template variables using the
:doc:`VarDumper component </components/var_dumper>`. When called without
arguments, all variables available in the template are dumped:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
arguments, all variables available in the template are dumped:
arguments, all variables available in the template are dumped,
including `app` global variable:


.. code-block:: twig

{# dumps a specific variable #}
{{ dump(user) }}

{# dumps multiple variables with labels #}
{{ dump(blog_posts: articles, user: app.user) }}
Comment on lines +567 to +568
Copy link
Copy Markdown
Contributor

@MrYamous MrYamous Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that available in Twig too ? It's not in Twig documentation either


{# dumps all template variables #}
{{ dump() }}

The ``dump()`` function is only available in the ``dev`` and ``test``
:ref:`configuration environments <configuration-environments>`.
It can also be used as a :ref:`tag <reference-twig-tag-dump>`.

.. seealso::

Read more about :ref:`debugging Twig templates <templates-debug-variables>`.

Workflow Functions
~~~~~~~~~~~~~~~~~~

The following functions are provided by the :doc:`Workflow component </workflow>`
to manage workflows and reduce the need of domain logic in your templates.

All workflow functions accept an optional ``name`` argument (the workflow name)
as the last parameter. This is only required when the object is associated with
multiple workflows:

.. code-block:: twig

{# if the object has only one workflow, the name is optional #}
{% if workflow_can(post, 'publish') %}

{# if the object has multiple workflows, specify the workflow name #}
{% if workflow_can(post, 'publish', 'blog_publishing') %}

Check failure on line 598 in reference/twig_reference.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Twig] Unexpected end of template.
.. _reference-twig-function-workflow-can:

**workflow_can**

.. code-block:: twig

{{ workflow_can(object, transition, name = null) }}

``object``
**type**: ``object``
``transition``
**type**: ``string``
``name`` *(optional)*
**type**: ``string`` | ``null`` **default**: ``null``

Returns ``true`` if the given object can make the given transition.

.. _reference-twig-function-workflow-transitions:

**workflow_transitions**

.. code-block:: twig

{{ workflow_transitions(object, name = null) }}

``object``
**type**: ``object``
``name`` *(optional)*
**type**: ``string`` | ``null`` **default**: ``null``

Returns an array with all the transitions enabled for the given object.

.. _reference-twig-function-workflow-transition:

**workflow_transition**

.. code-block:: twig

{{ workflow_transition(object, transition, name = null) }}

``object``
**type**: ``object``
``transition``
**type**: ``string``
``name`` *(optional)*
**type**: ``string`` | ``null`` **default**: ``null``

Returns a specific :class:`Symfony\\Component\\Workflow\\Transition` enabled for
the given object and transition name, or ``null`` if the transition is not enabled.

.. _reference-twig-function-workflow-marked-places:

**workflow_marked_places**

.. code-block:: twig

{{ workflow_marked_places(object, placesNameOnly = true, name = null) }}

``object``
**type**: ``object``
``placesNameOnly`` *(optional)*
**type**: ``boolean`` **default**: ``true``
``name`` *(optional)*
**type**: ``string`` | ``null`` **default**: ``null``

Returns an array with the place names of the given marking.

.. _reference-twig-function-workflow-has-marked-place:

**workflow_has_marked_place**

.. code-block:: twig

{{ workflow_has_marked_place(object, place, name = null) }}

``object``
**type**: ``object``
``place``
**type**: ``string``
``name`` *(optional)*
**type**: ``string`` | ``null`` **default**: ``null``

Returns ``true`` if the marking of the given object has the given place.

.. _reference-twig-function-workflow-transition-blockers:

**workflow_transition_blockers**

.. code-block:: twig

{{ workflow_transition_blockers(object, transition, name = null) }}

``object``
**type**: ``object``
``transition``
**type**: ``string``
``name`` *(optional)*
**type**: ``string`` | ``null`` **default**: ``null``

Returns :class:`Symfony\\Component\\Workflow\\TransitionBlockerList` for the
given transition.

.. _reference-twig-function-workflow-metadata:

**workflow_metadata**

.. code-block:: twig

{{ workflow_metadata(object, key, metadataSubject = null, name = null) }}

``object``
**type**: ``object``
``key``
**type**: ``string``
``metadataSubject`` *(optional)*
**type**: ``string`` | :class:`Symfony\\Component\\Workflow\\Transition` | ``null`` **default**: ``null``
``name`` *(optional)*
**type**: ``string`` | ``null`` **default**: ``null``

Returns the metadata for the given object. When ``metadataSubject`` is ``null``,
it returns the workflow metadata. Pass a place name (string) to get place
metadata, or a :class:`Symfony\\Component\\Workflow\\Transition` object to get
transition metadata:

.. code-block:: twig

{# workflow metadata #}
{{ workflow_metadata(blog_post, 'title') }}

{# place metadata #}
{{ workflow_metadata(blog_post, 'max_num_of_words', 'draft') }}

{# transition metadata #}
{{ workflow_metadata(blog_post, 'priority', workflow_transition(blog_post, 'to_review')) }}

.. seealso::

Read more about :doc:`Symfony Workflows </workflow>` and about
:ref:`storing metadata <workflow_storing-metadata>`.

WebLink Functions
~~~~~~~~~~~~~~~~~

The following functions are provided by the :doc:`WebLink component </web_link>`
to manage ``Link`` HTTP headers, enabling features like preloading resources and
`resource hints`_.

.. _reference-twig-function-preload:

**preload**

.. code-block:: twig

{{ preload(uri, attributes = {}) }}

``uri``
**type**: ``string``
``attributes`` *(optional)*
**type**: ``array`` **default**: ``{}``

Adds a ``Link`` HTTP header with ``rel="preload"`` to tell the browser to
start downloading the given resource as early as possible:

.. code-block:: html+twig

<link rel="preload" href="{{ preload('/fonts/myfont.woff2', {as: 'font'}) }}">

.. _reference-twig-function-dns-prefetch:

**dns_prefetch**

.. code-block:: twig

{{ dns_prefetch(uri, attributes = {}) }}

``uri``
**type**: ``string``
``attributes`` *(optional)*
**type**: ``array`` **default**: ``{}``

Adds a ``Link`` HTTP header with ``rel="dns-prefetch"`` to indicate an origin
that will be used to fetch required resources, and that should be resolved
as early as possible.

.. _reference-twig-function-preconnect:

**preconnect**

.. code-block:: twig

{{ preconnect(uri, attributes = {}) }}

``uri``
**type**: ``string``
``attributes`` *(optional)*
**type**: ``array`` **default**: ``{}``

Adds a ``Link`` HTTP header with ``rel="preconnect"`` to indicate an origin
that will be used to fetch required resources, initiating an early connection
(DNS lookup, TCP handshake, and TLS negotiation).

.. _reference-twig-function-prefetch:

**prefetch**

.. code-block:: twig

{{ prefetch(uri, attributes = {}) }}

``uri``
**type**: ``string``
``attributes`` *(optional)*
**type**: ``array`` **default**: ``{}``

Adds a ``Link`` HTTP header with ``rel="prefetch"`` to identify a resource that
might be required by the next navigation, so the browser can fetch it ahead of time.

.. _reference-twig-function-prerender:

**prerender**

.. code-block:: twig

{{ prerender(uri, attributes = {}) }}

``uri``
**type**: ``string``
``attributes`` *(optional)*
**type**: ``array`` **default**: ``{}``

.. deprecated::

Check failure on line 829 in reference/twig_reference.rst

View workflow job for this annotation

GitHub Actions / Lint (DOCtor-RST)

Please only provide ".. deprecated::" if the version is greater/equal "7.0"

Check failure on line 829 in reference/twig_reference.rst

View workflow job for this annotation

GitHub Actions / Lint (DOCtor-RST)

Please provide a numeric version behind ".. deprecated::" instead of ""

Check failure on line 829 in reference/twig_reference.rst

View workflow job for this annotation

GitHub Actions / Lint (DOCtor-RST)

Please provide a version behind ".. deprecated::"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. deprecated::
.. deprecated:: 6.4


The ``prerender`` resource hint is deprecated and superseded by the
`Speculation Rules API`_.

Adds a ``Link`` HTTP header with ``rel="prerender"`` to identify a resource that
might be required by the next navigation, so the browser can fetch and execute
it ahead of time.

.. _reference-twig-function-link:

**link**

.. code-block:: twig

{{ link(uri, rel, attributes = {}) }}

``uri``
**type**: ``string``
``rel``
**type**: ``string``
``attributes`` *(optional)*
**type**: ``array`` **default**: ``{}``

Adds a ``Link`` HTTP header with the given relation type. This can be used to
send any `link relation`_:

.. code-block:: html+twig

<link rel="alternate" href="{{ link('/index.jsonld', 'alternate') }}">

.. seealso::

Read more about the :doc:`WebLink component </web_link>`.

Form Related Functions
~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -1087,6 +1420,28 @@

This will set the default domain in the current template.

.. _reference-twig-tag-dump:

dump
~~~~

.. code-block:: twig

{% dump variable %}
{% dump variable1, variable2 %}

Dumps the given variables using the :doc:`VarDumper component </components/var_dumper>`.
Unlike the ``{{ dump() }}`` function which outputs inline, the tag sends
the output to the :doc:`web debug toolbar </profiler>`.

The ``dump`` tag is only available in the ``dev`` and ``test``
:ref:`configuration environments <configuration-environments>`.

.. seealso::

The :ref:`dump() function <reference-twig-function-dump>` can also be used
to dump variables inline.

.. _reference-twig-tag-stopwatch:

stopwatch
Expand Down Expand Up @@ -1121,3 +1476,6 @@
:ref:`Twig global app variable <twig-app-variable>`.

.. _`default filters and functions defined by Twig`: https://twig.symfony.com/doc/3.x/#reference
.. _`resource hints`: https://www.w3.org/TR/resource-hints/
.. _`link relation`: https://html.spec.whatwg.org/multipage/links.html#linkTypes
.. _`Speculation Rules API`: https://developer.mozilla.org/en-US/docs/Web/API/Speculation_Rules_API
Loading