In terms of:
- Speed
- Required processing (which will influence speed)
- 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 duplicat开发者_开发知识库ed, but the frontpage and other pages will each have their own dedicated file.
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.
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!
精彩评论