Where are the template files located in Drupal?
Normally template files reside in the theme folder. But sometimes custom modules may need to override the default template files — page, node, etc. — provided by Drupal. It can be tricky figuring out how to do this, so this page will present approaches for Drupal 5, 6, 7 and 8.
How are theme functions named in Drupal 7?
New in Drupal 7, theme functions can have preprocess functions just like templates. Copying and modifying template files are still considered more friendly for themers than overriding theme functions in template.php. Theme functions are named by prepending ‘theme_’ to the name of the hook.
Which is better Drupal 7 or template.php?
This is somewhat faster performance than loading template files. New in Drupal 7, theme functions can have preprocess functions just like templates. Copying and modifying template files are still considered more friendly for themers than overriding theme functions in template.php.
What is the theme hook function in Drupal?
Every chunk of output that is themed through the theme() function is called a theme hook. There are two ways to provide a default implementation. The easier way is to provide a function, and the recommended way is to provide a template and a corresponding preprocessor function. We’ll expand on this in a little bit.
How to add template suggestions in Drupal theme hook?
If a template.php file does not exist in your theme, you may create one. The prefix of “drop” should be the name of your theme. There are two ways to add these suggestions. The key of ‘ theme_hook_suggestion ‘ accepts a single suggestion and it takes precedence.
Is there a theme debug mode in Drupal?
As of Drupal 7.33, Drupal core has a theme debug mode that can be enabled and disabled via the theme_debug variable. Theme debug mode can be used to see possible template suggestions and the locations of template files right in your HTML markup (as HTML comments).
How to prefix a suggestion with a hook in Drupal?
All the suggestions set before it in core and modules would be lost. Prefix the suggestion with the name of the hook, it is associated with, such as “node” or “page”. This keeps it clear and the files grouped together. It also minimizes any chance of Drupal registering the template with a different hook.