Skip to content

Commit 1c25c7c

Browse files
authored
Explain why the Web Debug Toolbar is gone
When rendering a response using a template, the Web Debug Toolbar is gone, which was confusing to me. Only after searching I found the reason: there is no body element when using this rendering method. It seems logical to me to also explain extending a template to incorporate base.html.twig, so the Toolbar re-appears.
1 parent 600f5ae commit 1c25c7c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

page_creation.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,20 @@ to get your *new* lucky number!
262262

263263
http://localhost:8000/lucky/number
264264

265+
Now you may wonder where the Web Debug Toolbar has gone: that's because we don't write
266+
a ``body`` element using the current template. If we incorporate the default
267+
``base.html.twig``, which contains all default elements, including ``body``, you'll see
268+
that the Toolbar re-appears:
269+
270+
.. code-block:: diff
271+
272+
{# templates/lucky/number.html.twig #}
273+
+ {% extends 'base.html.twig' %}
274+
275+
+ {% block body %}
276+
<h1>Your lucky number is {{ number }}</h1>
277+
+ {% endblock %}
278+
265279
In the :doc:`/templating` article, you'll learn all about Twig: how to loop, render
266280
other templates and leverage its powerful layout inheritance system.
267281

0 commit comments

Comments
 (0)