Skip to content

Commit 21c9ad7

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: [Twig] [twig reference] add examples in yaml part
2 parents dacae59 + 56d0815 commit 21c9ad7

File tree

1 file changed

+77
-2
lines changed

1 file changed

+77
-2
lines changed

reference/twig_reference.rst

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,46 @@ yaml_encode
471471
``dumpObjects`` *(optional)*
472472
**type**: ``boolean`` **default**: ``false``
473473

474-
Transforms the input into YAML syntax. See :ref:`components-yaml-dump` for
475-
more information.
474+
Transforms the input into YAML syntax.
475+
476+
The ``inline`` argument is the level where the generated output switches to inline YAML:
477+
478+
.. code-block:: twig
479+
480+
{% set array = {
481+
'a': {
482+
'c': 'e'
483+
},
484+
'b': {
485+
'd': 'f'
486+
}
487+
} %}
488+
489+
{{ array|yaml_encode(inline = 0) }}
490+
{# output:
491+
{ a: { c: e }, b: { d: f } } #}
492+
493+
{{ array|yaml_encode(inline = 1) }}
494+
{# output:
495+
a: { c: e }
496+
b: { d: f } #}
497+
498+
The ``dumpObjects`` argument enables the dumping of PHP objects::
499+
500+
// ...
501+
$object = new \stdClass();
502+
$object->foo = 'bar';
503+
// ...
504+
505+
.. code-block:: twig
506+
507+
{{ object|yaml_encode(dumpObjects = false) }}
508+
{# output: null #}
509+
510+
{{ object|yaml_encode(dumpObjects = true) }}
511+
{# output: !php/object 'O:8:"stdClass":1:{s:5:"foo";s:7:"bar";}' #}
512+
513+
See :ref:`components-yaml-dump` for more information.
476514

477515
yaml_dump
478516
~~~~~~~~~
@@ -491,6 +529,43 @@ yaml_dump
491529
Does the same as `yaml_encode() <yaml_encode>`_, but includes the type in
492530
the output.
493531

532+
The ``inline`` argument is the level where the generated output switches to inline YAML:
533+
534+
.. code-block:: twig
535+
536+
{% set array = {
537+
'a': {
538+
'c': 'e'
539+
},
540+
'b': {
541+
'd': 'f'
542+
}
543+
} %}
544+
545+
{{ array|yaml_dump(inline = 0) }}
546+
{# output:
547+
%array% { a: { c: e }, b: { d: f } } #}
548+
549+
{{ array|yaml_dump(inline = 1) }}
550+
{# output:
551+
%array% a: { c: e }
552+
b: { d: f } #}
553+
554+
The ``dumpObjects`` argument enables the dumping of PHP objects::
555+
556+
// ...
557+
$object = new \stdClass();
558+
$object->foo = 'bar';
559+
// ...
560+
561+
.. code-block:: twig
562+
563+
{{ object|yaml_dump(dumpObjects = false) }}
564+
{# output: %object% null #}
565+
566+
{{ object|yaml_dump(dumpObjects = true) }}
567+
{# output: %object% !php/object 'O:8:"stdClass":1:{s:3:"foo";s:3:"bar";}' #}
568+
494569
abbr_class
495570
~~~~~~~~~~
496571

0 commit comments

Comments
 (0)