Skip to content

add missing twig dump construct #9042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions templating/debug.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,25 @@ for example, inside your controller::
The output of the ``dump()`` function is then rendered in the web developer
toolbar.

The same mechanism can be used in Twig templates thanks to ``dump()`` function:
In a Twig template, you can use the ``dump`` utility as a function or a tag:

* ``{% dump foo.bar %}`` is the way to go when the original template output
shall not be modified: variables are not dumped inline, but in the web
debug toolbar;
* on the contrary, ``{{ dump(foo.bar) }}`` dumps inline and thus may or not
be suited to your use case (e.g. you shouldn't use it in an HTML
attribute or a ``<script>`` tag).

.. code-block:: html+twig

{# app/Resources/views/article/recent_list.html.twig #}
{{ dump(articles) }}
{# the contents of this variable are sent to the Web Debug Toolbar #}
{% dump articles %}

{% for article in articles %}
{# the contents of this variable are display on the web page #}
{{ dump(article) }}

<a href="/article/{{ article.slug }}">
{{ article.title }}
</a>
Expand Down