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:


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

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

    # 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
    # Not recommended in production environments
    # @default false
    debug: true

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



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