8000 add serialize reference by jrushlow · Pull Request #15039 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

add serialize reference #15039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions reference/twig_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,29 @@ project's root directory:
If the given file path is out of the project directory, a ``null`` value
will be returned.

serialize
~~~~~~~~~

.. code-block:: twig

{{ object|serialize(format = 'json', context = []) }}

``object``
**type**: ``mixed``

``format`` *(optional)*
**type**: ``string``

``context`` *(optional)*
**type**: ``array``

.. versionadded:: 5.3

The ``serialize`` filter was introduced in Symfony 5.3.

Accepts any data that can be serialized by the :doc:`Serializer component </serializer>`
and returns a serialized string in the specified ``format``.

.. _reference-twig-tags:

Tags
Expand Down
13 changes: 13 additions & 0 deletions serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ you need it or it can be used in a controller::
}
}

Or you can use the ``serialize`` Twig filter in a template:

.. code-block:: twig

{{ object|serialize(format = 'json') }}

See the :doc:`twig reference </reference/twig_reference>` for
more information.

.. versionadded:: 5.3

A ``serialize`` filter was introduced in Symfony 5.3 that uses the Serializer component.

Adding Normalizers and Encoders
-------------------------------

Expand Down
0