I'm trying to create a new theme for my Drupal site, using the phptemplate theme engine. I would like to have the front page of my site have some content that isn't found on the rest of the site, and I'd like to create a template specific to the front page to accommodate this.

Is it possible to create something like an index.tpl.php template that will only be used as the front page of the site, with page.tpl.php used for everything else?

Comments

eaton’s picture

If you only want to display a 'splash page' or something like that, you might be able to just use frontpage.module. If you want a subtly different template file entirely, it's a bit trickier but still very doable.

First, create a template.php file and putting it in your theme's directory. Them stick the following function should be in the file:

<?php
function _phptemplate_variables($hook, $variables) {
  extract($variables);
  $vars = array();

  switch ($hook) {
    case 'page':
      if (drupal_is_front_page()) {
        $vars['template_file'] = 'frontpage.tpl.php';
      }
      break;
  }
  
  return $vars;
}
?>

That will override the normal template file if you're currently on the front page. This feature will (hopefully) be included by default in the next version of Drupal, but for the meantime editing your template.php file will do.

--
Eaton's blog | VotingAPI discussion

--
Eaton — Partner at Autogram