How to enable theme suggestions in Drupal 9?

By toswebdev, 5 October, 2022
How to enable theme suggestions in Drupal 9?

Edit services configuration for your Drupal site, for default location, should be:

/sites/default/services.yml

If the folder is correct, but you don't have a services.yml file, rename default.services.yml to services.yml.

Find twig.config section and change debug parameter to true:
 

 twig.config:
    # Twig debugging:
    #
    # When debugging is enabled:
    # - The markup of each Twig template is surrounded by HTML comments that
    #   contain theming information, such as template file name suggestions.
    # - Note that this debugging markup will cause automated tests that directly
    #   check rendered HTML to fail. When running automated tests, 'debug'
    #   should be set to FALSE.
    # - The dump() function can be used in Twig templates to output information
    #   about template variables.
    # - Twig templates are automatically recompiled whenever the source code
    #   changes (see auto_reload below).
    #
    # For more information about debugging Twig templates, see
    # https://www.drupal.org/node/1906392.
    #
    # Not recommended in production environments
    # @default false
    debug: true

After clearing the cache you will see html comments for every block etc.

Tags

Comments

All comments go through moderation, so your comment won't display immediately.