Search code examples
drupaldrupal-theming

Is it better to use a separate template file for the front page?


In terms of:

  1. Speed
  2. Required processing (which will influence speed)
  3. Following standards

Which of the following two methods will be better?

I want to create a general page layout, however, the frontpage will look different from the normal look and feel.

Method 1

Creating a normal page.tpl.php file but with the following code in it:

.....
<body>
  <?php if (isFront()) { 
          // lots of stuff for the frontpage
        }
        else 
        {
          // lots of stuff for the other pages
        }
  ?>
</body>

Method 2

Creat two distinct pages, namely page.tpl.php and front.tpl.php. Code will be duplicated, but the frontpage and other pages will each have their own dedicated file.


Solution

  • I would say that method 2 is better. I think speed will not be greatly affected either way, and there are no strict standards about this, but excessive branching in template files is discouraged.

    However I would be interested to see what the homepage specific code is. Drupal will give the front page a "front" css class so it can be styled differently and blocks can be created to display only on the front page. So there may not be a need for a specific front page template.