3

Why isn't the Twig debug working on my Drupal 8.2.6 site?

This is the folder structure.

File structure

These are the folder permissions.

Folder permissions

This is the content of the settings.php file.

$settings['hash_salt'] = 'DEVELOPMENT_SALT';
$settings['update_free_access'] = FALSE;
$settings['file_public_base_url'] = 'http://localhost/files';
$settings['file_public_path'] = 'sites/default/files';
$settings['file_private_path'] = 'sites/default/private';
$settings['file_scan_ignore_directories'] = [
  'node_modules',
  'bower_components',
];
if (file_exists(__DIR__ . '/../development/settings.development.php'))     {
  include __DIR__ . '/../development/settings.development.php';
}

Here I include /../development/settings.development.php.

assert_options(ASSERT_ACTIVE, TRUE);
\Drupal\Component\Assertion\Handle::register();

/**
 * Enable local development services.
 */
$settings['container_yamls'][] = __DIR__ . '/development.services.yml';

$databases['default']['default'] = array(
  'database' => 'dbname',
  'username' => 'dbusername',
  'password' => 'pw',
  'prefix' => '',
  'host' => '127.0.0.1',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

$settings['hash_salt'] = 'DEVELOPMENT';

$config['system.logging']['error_level'] = 'verbose';
$config['system.performance']['css']['preprocess'] = FALSE;
$config['system.performance']['js']['preprocess'] = FALSE;
$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] =     'cache.backend.null';
$settings['extension_discovery_scan_tests'] = TRUE;
$settings['rebuild_access'] = TRUE;
$settings['skip_permissions_hardening'] = TRUE;

Here I also add development.services.yml.

parameters:
  http.response.debug_cacheability_headers: true
  twig.config:
    debug: true
    auto_reload: true
    cache: false
services:
  cache.backend.null:
    class: Drupal\Core\Cache\NullBackendFactory

Things I have checked/done:

  • Checked if all these files are loaded -> They are
  • Checked the indentation of the development.services.yml -> Checks out
  • Cleared all the different caches, rebuild them, etc -> If I change a template, it changes, but no Twig debugging

sites/default/files AND sites/default/private are not used by Drupal.

2

Try to change your development.services.yml to following. this works for me correctly(I hope works for you too) .

services:
  cache.backend.null:
    class: Drupal\Core\Cache\NullBackendFactory

# Enable Twig debugging.
parameters:
 twig.config:
   debug: true
   auto_reload: true
   cache: false

also this article about setting up debugging on Drupal 8 is very good for future visitors of this question.

  • Thanks! This is the formatting that finally worked for me. – Robb Davis Mar 6 '18 at 21:04
  • @RobbDavis you're welcome, good to hear that. – Yusef Mohamadi Mar 7 '18 at 11:27
1

Services should come before parameters ...also... If you don't want to enable all the 'stuff' you have in settings.local.php you can just add... $settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';
to the bottom of your settings.php file to turn on twig debug after adding the parameters to development.services.yml.

I use both this and...

if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {
   include $app_root . '/' . $site_path . '/settings.local.php';

Commenting out one or the other depending on what I need.

0

It seems everything is correct and I guess you just forget check "Show comments" on your browser.

enter image description here

  • This is not the case, because I am using Chrome's inspector. – user3634184 Mar 15 '17 at 8:58
  • @user3634184 try to check it on firefox ,just for test. – Yusef Mohamadi Mar 15 '17 at 9:58
  • @user3634184 did you check my another answer? plz don't forget clear the cache. – Yusef Mohamadi Mar 15 '17 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.