Skip to content

Commit af6b4de

Browse files
authored
add missing twig dump construct
added missing {% dump foo %} construct, in addition to {{ dump(foo) }}. The first one if the only one dumping to the debug toolbar. NB: copy pasted from the var_dumper component doc : https://symfony.com/doc/2.8/components/var_dumper.html
1 parent 3539693 commit af6b4de

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

templating/debug.rst

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,31 @@ for example, inside your controller::
3333
The output of the ``dump()`` function is then rendered in the web developer
3434
toolbar.
3535

36-
The same mechanism can be used in Twig templates thanks to ``dump()`` function:
36+
In a Twig template, two constructs are available for dumping a variable.
37+
Choosing between both is mostly a matter of personal taste, still:
38+
39+
* ``{% dump foo.bar %}`` is the way to go when the original template output
40+
shall not be modified: variables are not dumped inline, but in the web
41+
debug toolbar;
42+
* on the contrary, ``{{ dump(foo.bar) }}`` dumps inline and thus may or not
43+
be suited to your use case (e.g. you shouldn't use it in an HTML
44+
attribute or a ``<script>`` tag).
3745

3846
.. code-block:: html+twig
3947

48+
{# app/Resources/views/article/recent_list.html.twig #}
49+
{% dump articles %}
50+
51+
{% for article in articles %}
52+
<a href="/article/{{ article.slug }}">
53+
{{ article.title }}
54+
</a>
55+
{% endfor %}
56+
57+
or
58+
59+
.. code-block:: html+twig
60+
4061
{# app/Resources/views/article/recent_list.html.twig #}
4162
{{ dump(articles) }}
4263

0 commit comments

Comments
 (0)