Debug Templates
If you need a custom template for output, e.g. for a frontend list, or want to know which attributes are being passed to an existing template, you can conveniently output them using the Symfony debug toolbar.
The default template is “metamodel_prerendered”, or whichever template was selected in the render setting for output.
If no custom template is in use yet, a copy of “metamodel_prerendered” must be created in the Contao “/templates” folder.
The template is extended with the following lines at the top:
1<?php
2// Debug items.
3if (\Contao\System::getContainer()->get('kernel')->isDebug()) {
4 dump($this->data);
5}
6?>
The page must then be viewed in the frontend in debug mode. To do this, enable debug mode in the backend header, or for persistent debug mode, create a .env or .env.local file in the project folder with the content APP_ENV=dev (the page should then not be publicly accessible).
The array can then be inspected in the debug toolbar via the “crosshair icon”:

The isDebug() check ensures that the dump does not interfere with the normal page call.
From MM 2.2 there is a dedicated template metamodel_prerendered_debug.html5 that can be selected in the render settings for frontend output — no MM list values will be output with this template initially.
For easy copying of the array data into a frontend template, there is the Array Helper, which generates output in the source code for copy & paste.
Debug in MM 2.0
In Contao 3, the Symfony toolbar is not available and print_r must be used instead.
The template is extended with some output lines and should start as follows:
1<?php
2echo "<!-- DEBUG START \n";
3echo "<pre>\n";
4print_r($this->items->parseAll($this->getFormat(), $this->view));
5echo "</pre>\n";
6echo "\n DEBUG END -->";
7?>
When the corresponding page with the listing is opened in the browser, the debug output should appear in the page source.
If the output is very large, rendering in the browser can become very slow — a workaround is to only output a single item node:
1<?php
2echo "<!-- DEBUG START \n";
3echo "<pre>\n";
4// only 0th node
5print_r($this->items->parseAll($this->getFormat(), $this->view)[0]);
6echo "</pre>\n";
7echo "\n DEBUG END -->";
8?>
If the redirect and filter for the detail page are configured in the render settings, the array output in the source code can become very large and often causes an “Allowed memory size…” error. A workaround is to temporarily disable the redirect filter.
The output can be removed by commenting out, deleting, or switching to a different template.