Skip to content

Commit 346ea4b

Browse files
Sarah-eitjaviereguiluz
authored andcommitted
[Twig] [twig reference] add examples in yaml part
1 parent da70070 commit 346ea4b

File tree

1 file changed

+71
-2
lines changed

1 file changed

+71
-2
lines changed

reference/twig_reference.rst

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,43 @@ yaml_encode
483483
``dumpObjects`` *(optional)*
484484
**type**: ``boolean`` **default**: ``false``
485485

486-
Transforms the input into YAML syntax. See :ref:`components-yaml-dump` for
487-
more information.
486+
Transforms the input into YAML syntax.
487+
488+
The ``inline`` argument is the level where you switch to inline YAML:
489+
490+
.. code-block:: twig
491+
492+
{% set array = {
493+
'a': {
494+
'c': 'e'
495+
},
496+
'b': {
497+
'd': 'f'
498+
}
499+
} %}
500+
501+
{{ array|yaml_encode(inline = 0) }}
502+
{# output: { a: { c: e }, b: { d: f } } #}
503+
504+
{{ array|yaml_encode(inline = 1) }}
505+
{# output: a: { c: e } b: { d: f } #}
506+
507+
The ``dumpObjects`` argument is used to dump objects::
508+
509+
// ...
510+
$object = new \stdClass();
511+
$object->foo = 'bar';
512+
// ...
513+
514+
.. code-block:: twig
515+
516+
{{ object|yaml_encode(dumpObjects = false) }}
517+
{# output: null #}
518+
519+
{{ object|yaml_encode(dumpObjects = true) }}
520+
{# output: !php/object 'O:8:"stdClass":1:{s:5:"foo";s:7:"bar";}' #}
521+
522+
See :ref:`components-yaml-dump` for more information.
488523

489524
yaml_dump
490525
~~~~~~~~~
@@ -503,6 +538,40 @@ yaml_dump
503538
Does the same as `yaml_encode() <yaml_encode>`_, but includes the type in
504539
the output.
505540

541+
The ``inline`` argument is the level where you switch to inline YAML:
542+
543+
.. code-block:: twig
544+
545+
{% set array = {
546+
'a': {
547+
'c': 'e'
548+
},
549+
'b': {
550+
'd': 'f'
551+
}
552+
} %}
553+
554+
{{ array|yaml_dump(inline = 0) }}
555+
{# output: %array% { a: { c: e }, b: { d: f } } #}
556+
557+
{{ array|yaml_dump(inline = 1) }}
558+
{# output: %array% a: { c: e } b: { d: f } #}
559+
560+
The ``dumpObjects`` argument is used to dump objects::
561+
562+
// ...
563+
$object = new \stdClass();
564+
$object->foo = 'bar';
565+
// ...
566+
567+
.. code-block:: twig
568+
569+
{{ object|yaml_dump(dumpObjects = false) }}
570+
{# output: %object% null #}
571+
572+
{{ object|yaml_dump(dumpObjects = true) }}
573+
{# output: %object% !php/object 'O:8:"stdClass":1:{s:3:"foo";s:3:"bar";}' #}
574+
506575
abbr_class
507576
~~~~~~~~~~
508577

0 commit comments

Comments
 (0)