How to Print Variables using Devel and Kint in Drupal
As a Drupal developer, you will often want to inspect variables in your modules or themes to view the actual values. PHP has default functions such as var_dump()
and print_r()
that will print all the information but it’s not very intuitive nor printed in an easy to understand way. In most cases, it prints too much information and it can be time-consuming to find the variable you actually want by filtering through all the arrays and methods.
Using Devel and the Devel Kint Extras modules, you can print variables in a more user-friendly way.
This tutorial will walk through how to set up these modules so you can print variables in PHP and Twig using Kint.