Mike Cho Development

Turn on debugging in Drupal

When you’re doing custom theming in Drupal, you’ll want to have debugging enabled. This lets you peek into your code and see what’s going on.

This has an equivalent in WordPress, which only requires modifying one line of code. As is usual in Drupal, expect a bit more configuring.

Navigate to the following directory:

⋁ YourSite
  > core
  > modules
  > profiles
  ⋁ sites
    ⋁  default
      > files

That’s YourSite/sites/default

See the !default.services.yml (I pronouce it, “yammel”)?

Duplicate or copy that file. The duplicate file will be called services.yml.

Now, if you open services.yml, you’ll find a bunch of curious-looking, commented-out code. Scroll down to where it says:

debug: false

Change it so that it says:

debug: true

The hard part is over!

Now go back to your backend, to Configuration/Performance/Clear All Caches. Smash that button, as the YouTubers say…

Now if you go back to your site and right-click + Inspect (CTRL-SHIFT-I on Windows: someday, I’ll remember that), you’ll see a bunch of commented code that you never wrote.

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'toolbar' -->
<!-- BEGIN OUTPUT FROM 'core/themes/stable/templates/navigation/toolbar.html.twig' -->

If you see that–congratulations! You successfully turned on debugging. Incredible riches and good times await.

  1. March 26, 2021 - Reply

    Hi, good job, I ended up referring to this blog that I wrote 4 days ago. Must be helpful! 🙂