May 12, 2021
Written by: Jon Kamke
How to add a custom template suggestion.
Drupal 7 has a solid system of template suggestions for overriding certain types of content, but sometimes it’s necessary to add a custom template suggestion. The following code adds a page template suggestion for the content types.
/**
* Implements HOOK_preprocess_page().
*/
function HOOK_preprocess_page(&$variables) {
// Add template suggestions for content type.
if (isset($variables['node']->type)) {
$variables['theme_hook_suggestions'][] = 'page__' . $variables['node']->type;
}
}
In the theme add page—article.tpl.php where article is the content type name.