Enable Debugging in Twig Templates?
Twig is a contemporary, quick, and secure template framework that assists developers in creating new templates and successfully changing old templates.
There are several distinctions between PHP templates and Twig. Twig has its own set of grammar and coding conventions.
The debugging is significantly easier to enable with Drupal 8. Twig debugging makes it easier for developers to identify template names.
The theme_suggestions hook allows them to build new template naming systems. In the sites/default directory, every Drupal 8 site has a default.services.yml file. Change the name to services.yml.
There is a twig.config argument in that services.yml file. Change the debug value from false to true, but leave the auto_reload and cache variables at false. Save the work and clear the cache.
How to Enable Twig Debugging?
There are several methods or choices for enabling twig theme debugging. This is the most basic way.
Follow the steps below in order to enable twig template debugging by making modifications to services.yml:
- Firstly go to the /sites/default folder.
- Rename the default.services.yml file to services.yml.
- Locate ‘twig.config’ in the services.yml file.
- Debug should be set to true.
- Head to the sites folder as the next step to enable Debugging in Twig Templates
- After that, we have to open the development.services.yml file. In the file type in the following code:
twig.config:
debug: true
auto_reload: true
cache: false - Make a duplicate of the example.settings.local.php file and rename it settings.local.php.
- Uncomment the commandine given below:
$settings['cache']['bins']['render'] = 'cache.backend.null';
- Locate the following code block in the settings.php file.
if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {
include $app_root . '/' . $site_path . '/settings.local.php';
} - Paste the command line at the bottom of the file.
- Finally, we have to clear the cache to complete the whole process.
Examine the browser’s inspector to view all of the available template recommendations in the code, as well as which templates are currently being utilized.
Enabling Twig Debugging With Drupal Console
If we use the Drupal console, we can carry out all of this with a single command
drupal site:mode dev
However, before uploading the site, remember to re-enable production settings:
drupal site:mode prod
We have to do this before uploading the site to the server.
[Need assistance with similar queries? We are here to help]
Conclusion
To sum up we have now seen how to Enable Debugging in Twig Templates with the support of our tech support team.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
0 Comments