Enable Twig debug via Devel PHP

Components

Enabling Twig debug info via Devel PHP is not something I recommend you to do but in some rare cases, you might have to do it. Here's how to do it:

use Symfony\Component\Yaml\Yaml;

$yaml = Yaml::parseFile('sites/default/default.services.yml');
$yaml['parameters']['twig.config']['debug'] = TRUE;
$updated_yaml = Yaml::dump($yaml);
file_put_contents('sites/default/services.yml', $updated_yaml);

Nothing fancy here. Just loading the default services file, changing one variable to TRUE and then saving the content to services.yml file.

About the Author

Goran Nikolovski is a creator, speaker, open-source contributor, web developer specializing in Drupal and DevOps enthusiast. He is the founder of this website and he enjoys sharing his knowledge. Need help with anything related to Drupal? Get in touch.