phpdrupal-7drupal-theming

Drupal 7 not using the template suggestion


I have added the following to my template.php file, in the [themename]_preprocess_page function:

<?php
  if ($variables['is_front'])
  {
    $variables['theme_hook_suggestions'] = array();
    $variables['theme_hook_suggestions'][] = 'page__index';
  }

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

If I run a var_dump on the $variables array, I can see that, on my front page, the 'theme_hook_suggestions' is set to only use 'page__index'. I have a file named 'page--index.tpl.php'. Drupal still uses page.tpl.php.

I also commented out the code above, and renamed the file to 'page--front.tpl.php' and it still used page.tpl.php. I clear the caches after every change.

What am I missing?

Edit: To help clarify, I want to override the entire design of the page for the front - no columns or sidebars, different graphics, different backgrounds on some of the div's, etc. I don't want to override the 'node--' template files (yet).

In the end, I need to have a static front page with a different design than the rest of the site, then a custom node template for each content type.


Solution

  • I worked with the awesome folks on the #drupal IRC channel and found the issue. Not sure if this is a bug in the code or on purpose - but you cannot use the word 'index' for those theme suggestions. I changed the content type's name to 'homepage' and voila!