Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal 7 How to override page.tpl for specific content type?

I wanted to override page.tpl.php for specific content type. I have tried these thing, nothing works for me.

  1. page--article.tpl.php
  2. page--node--article.tpl.php
  3. page--node--type--article.tpl.php
  4. page--node-type--article.tpl.php
  5. page--type--article.tpl.php

But when I targetted specific node by number i.e. page--node--8.tpl.php it worked fine. I think page--article.tpl.php should have worked, but I dont know why its not working.

Please tell me if I am naming it wrong. and how can I debug such things. I have heard I can use Devel module, but know nothing about it. A slight hint in right direction will be appreciated.

Thanks in advance

like image 652
Rahul Prasad Avatar asked Jun 25 '12 17:06

Rahul Prasad


People also ask

What is TPL file in Drupal?

tpl. php file returns the HTML for a single Drupal page.


1 Answers

You have to make sure that your template can handle this ... I got a code snippet that worked for me here:

http://drupal.org/node/1089656#comment-4426790

<?php
function themeName_preprocess_page(&$vars, $hook) {
  if (isset($vars['node'])) {
    // If the node type is "blog_madness" the template suggestion will be "page--blog-madness.tpl.php".
    $vars['theme_hook_suggestions'][] = 'page__'. $vars['node']->type;
  }
}
?>
like image 75
BeWhy Avatar answered Sep 20 '22 17:09

BeWhy