Drupal 7 Node Type Based Custom Template

In many cases of theming in Drupal we may may need a different set of header and footer. We can achieve this by writing a couple of lines in template.php for your current Drupal theme. Code snippet for Drupal 7 node type based custom template.

function yourthemename_preprocess_page(&$vars) {
  
  if (!empty($vars['node']) && !empty($vars['node']->type)) {
    $vars['theme_hook_suggestions'][] = 'page__node__' . $vars['node']->type;
  }

}

Suppose you have to make separate set of look for book pages with smaller header and footer bar to give larger space to book, you can try this code in your theme template. All you need to name your file like this – page-node-book.tpl.php and see the magic.

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x