Debugging & Tracy

Theme Redone uses Nette’s Tracy Debugger out of the box. It is imported and defined in the [theme-root]/php-inc/latte.php file, where the Latte engine is initialized as well.

Before going live, we suggest either commenting out or removing these 2 lines:

[theme-root]/php-inc/latte.phpuse Tracy\Debugger;
Debugger::enable();

Here’s a quick demo of how it’s used, and for more info, we encourage you to read their official documentation.

Catching bugs early

In the case of syntax or logic errors, Tracy would show a screen such as the one below. For this example we made a mistake not writing the closing ) parenthesis for the the_content() WordPress function.

<div class="content">
  {the_content(}
</div>

Error screen thrown by Tracy:
Tracy Debugger error screen example


Logging

When it comes to logging, we have two options with Tracy.

  • Logging in-place – dump() function
  • Logging to the Tracy debug bar – bdump() function

We’ll use the same simple example for both cases.

Let’s say we have this array that we want to log (It might be coming from the database).

{var $test_arr = [
  [
    'id' => 1,
    'name' => 'Jane Doe'
  ],
  [
    'id' => 2,
    'name' => 'John Doe'
  ]
]}

To log this array in place, we would use Tracy’s dump() function like so.

{do dump($test_arr)}

This would be the result of calling the dump() function.
Tracy dump function example | theme-redone


To log to Tracy’s debug bar, we would call the bdump() function.

{do bdump($test_arr)}

Now, the logged array would be shown inside Tracy’s debug bar, like so.
Tracy's bdump function example

Join Our Newsletter

To get updates about Theme Redone