8000 feature #15039 add serialize reference (jrushlow) · symfony/symfony-docs@79c31b9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 79c31b9

Browse files
committed
feature #15039 add serialize reference (jrushlow)
This PR was squashed before being merged into the 5.3-dev branch. Discussion ---------- add serialize reference add docs for the new `serialize` filter provided by `TwigBridge` Commits ------- 91096d5 Add serialize reference
2 parents 85c30da + 91096d5 commit 79c31b9

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

reference/twig_reference.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,29 @@ project's root directory:
558558
If the given file path is out of the project directory, a ``null`` value
559559
will be returned.
560560

561+
serialize
562+
~~~~~~~~~
563+
564+
.. code-block:: twig
565+
566+
{{ object|serialize(format = 'json', context = []) }}
567+
568+
``object``
569+
**type**: ``mixed``
570+
571+
``format`` *(optional)*
572+
**type**: ``string``
573+
574+
``context`` *(optional)*
575+
**type**: ``array``
576+
577+
.. versionadded:: 5.3
578+
579+
The ``serialize`` filter was introduced in Symfony 5.3.
580+
581+
Accepts any data that can be serialized by the :doc:`Serializer component </serializer>`
582+
and returns a serialized string in the specified ``format``.
583+
561584
.. _reference-twig-tags:
562585

563586
Tags

serializer.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ you need it or it can be used in a controller::
4141
}
4242
}
4343

44+
Or you can use the ``serialize`` Twig filter in a template:
45+
46+
.. code-block:: twig
47+
48+
{{ object|serialize(format = 'json') }}
49+
50+
See the :doc:`twig reference </reference/twig_reference>` for
51+
more information.
52+
53+
.. versionadded:: 5.3
54+
55+
A ``serialize`` filter was introduced in Symfony 5.3 that uses the Serializer component.
56+
4457
Adding Normalizers and Encoders
4558
-------------------------------
4659

0 commit comments

Comments
 (0)
0