Twig debug

{{ dump() }}
{{ dump(variable_name) }}

List available variables (at top level):

{{ dump(_context|keys) }}

If you have Devel module, you can get an accordion display of the variables available to twig with:

{{ devel_dump() }}

Debugging with console.log
We can add the following to a twig template and view the logs in the browser:

<script>console.log({{ _context | json_encode | raw}});</script>

Enable Twig debug mode in Drupal 10

drush twig:debug on && \
drush state:set disable_rendered_output_cache_bins 1 --input-format=integer  && \
drush cache:rebuild

Disable Twig debug mode in Drupal 10

drush twig:debug off && \
drush state:set disable_rendered_output_cache_bins 0 --input-format=integer && \
drush cache:rebuild