What is template.php in Drupal?

The template.php file in the theme directory allows you to override a theme function.

In Drupal, template.php (previously known as template.php in Drupal 7 and earlier versions) is a file used to hold theme-specific PHP functions. However, in Drupal 8 and later versions, the theme-related PHP functions have been moved to the *.theme file (e.g., mytheme.theme).

Here’s how you can structure the functions in a *.theme file:

php
/**
* Implements hook_preprocess_HOOK() for node templates.
*/

function mytheme_preprocess_node(&$variables) {
// Your preprocessing logic here.
}

/**
* Implements hook_theme_suggestions_HOOK_alter() for node templates.
*/

function mytheme_theme_suggestions_node_alter(array &$suggestions, array $variables) {
// Your suggestion altering logic here.
}

So, if you’re asked about template.php in a Drupal interview, you should clarify whether the question pertains to Drupal 7 or earlier versions (where template.php is relevant) or Drupal 8 and later versions (where *.theme files are used instead). If it’s about Drupal 8 or later, you would want to discuss the *.theme file and its role in theme development.