views:

52

answers:

2

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.

+2  A: 

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.

Jeremy French
The structure of the frontpage looks completely different. I'll see if I can post a link here once the site is done. I'm probably going to go with method 1, because I don't want to have to change any <HEAD> info, or other stuff in two templates files, even though changes there are extremely unlikely.
RD
Branching in a template like this is bad because it doesn't work very well if you have some of Drupal's more aggressive cache features (both core and contributed) enabled. If, after the cache is cleared, the front page is the next page to be loaded, then *every* page will look like the front page, and vice versa.
Garrett Albright
It is more conventional to have separate files, and following convention helps other developers come up to speed on what you've built.
Grayside
+2  A: 

I will tackle your points in reverse order:

STANDARDS

I believe the standard accepted method (at least when working with zen-based themes) is to create a specific template. You actually do not need to put any additional theming function for it to work, as if you name it page-front.tpl.php it will be used exclusively for the front page. This of course applies only if you really need a separate template (see Jeremy's answer about this).

REQUIRED PROCESSING

I don't think there is a perceivable difference intimately connected with the nature of the two different methods. Everything else being the same, it's still a matter for the computer to open a file (the template) and process the PHP in it, whether this is the same file or another one. Solution #1 has an if statement more but... does it really make a difference?

SPEED

If you are really in bad need for optimisation, I read (if I am not wrong on Pro Drupal Development) that theming a page via a template is 5x times slower than doing it via a function, so you might consider that solution too, although this would only bring a benefit if the homepage is not cacheable, I believe.

HTH!

mac