Difference between template suggestions in Drupal 6 and Drupal 7?

Before we move on to discuss the difference between template suggestion in Drupal 6 and Drupal 7, I would like to give a brief introduction about template suggestions. Template suggestion is an alternate template file which is created to override the

base tpl file. Suppose you have a content type and you want to display the content of that content type different than other. In such case you need to use the template suggestion.

Please note suggestion would work only if they are placed in the same directory i.e the base template and inherited template.

Here in my example I am using a collection content type for which I will be using the template suggestion.
In Drupal 7, for front page the template suggestion is page–front.tpl.php. In Drupal 7 all the template suggestion are in $vars[‘theme_hook_suggestions’] array. So write the following lines of code in enabled theme template.php file. In template.php find yourThemeName_preprocess_page() function and put the following lines into it.

if (isset($vars['node'])) {
  // If the node type is "collection" the template suggestion will be "page--collection.tpl.php".
   $vars['theme_hook_suggestions'][] = 'page__'. str_replace('_', '--', $vars['node']->type);

Now create a page–collection.tpl.php file and put your code there. Dont forget to clear the cache after this. The code which you have written in the page–collection.tpl.php will run if you visit the collection page.

For those who still using Drupal 6 here are the steps to use template suggestion. In Drupal 6, the template suggestion are in $vars[‘template_files’] array. Use the following code in your template.php file preprocess_page() function.

    if ($vars['node']->type != "") {
		$vars['template_files'][] = "page-node-" . $vars['node']->type;

The template suggestion for collection would be page-node-collection.tpl.php. Clears the cache and run the page.
This is all about page template suggestion for Drupal 6 and Drupal 7.

  1. Marina
  2. Thaiyung
  3. Michale
  4. Steve
  5. buy flexeril online
  6. Motrin
  7. Wendi
  8. Willa
  9. Barry

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Skip to toolbar