From 91096d5fbb61cb3209e97524732191062bc11a9e Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Fri, 26 Feb 2021 19:05:50 -0500 Subject: [PATCH] Add serialize reference --- reference/twig_reference.rst | 23 +++++++++++++++++++++++ serializer.rst | 13 +++++++++++++ 2 files changed, 36 insertions(+) diff --git a/reference/twig_reference.rst b/reference/twig_reference.rst index 270c9c678c8..e4991845096 100644 --- a/reference/twig_reference.rst +++ b/reference/twig_reference.rst @@ -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 ` +and returns a serialized string in the specified ``format``. + .. _reference-twig-tags: Tags diff --git a/serializer.rst b/serializer.rst index b4dd7e03d52..7d526ae46bc 100644 --- a/serializer.rst +++ b/serializer.rst @@ -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 ` for +more information. + +.. versionadded:: 5.3 + + A ``serialize`` filter was introduced in Symfony 5.3 that uses the Serializer component. + Adding Normalizers and Encoders ------------------------------- pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy