I have the following problem:

I'm trying to make a sub-theme to the popular Zen theme which will have a custom front page. I want to use a separate template file for my homepage, so I tried using page-front.tpl.php, but it just doesn't work.

If I put page-front.tpl.php in Zen's directory and set Zen as the default theme, the custom front page works fine, but if I just put it in my sub-theme's directory, where it should be, nothing happens, it's just ignored. I've tried "Clear cache data", I have both the base theme and the sub-theme enabled... just don't have any clue what I should do now.

Should something in template.php or .info file be changed? (don't think so, but I'm really deperate and to the point of just giving up on drupal, after seeing that too many things that should "just work" seem almost imposible or extremely complicated in this cms...)

Comments

jayboodhun’s picture

Hi,

Copy all the code from your page.tpl.php, create a new file called page-default.tpl.php and paste the code in there.
Now delete all the code from your page.tpl.php and add the following:

<?php
// Loads the front page template
if ($is_front) {
    include 'page-front.tpl.php'; 
    return; }

//Adding custom template based on content types
if ($node->type=='story') {
    include 'page-story.tpl.php'; 
    return; }

//if none of the above applies, load the page-default.tpl.php 
include 'page-default.tpl.php'; 
    return;
?>

That should work.

neuronq’s picture

thanks! it works ...but I wonder: is this the "normal" way to do it? I mean, is there a reason why things work without this in a theme but not if you're sub-theme-ing? Is it a "design error" of PHPTemplate or is this how things are supposed to work for some reasons that are beyond a newbie like me?
...or maybe I should just stop asking myself stupid questions and go get thing done :)

jayboodhun’s picture

Hey, glad this worked for you.
This was one of the first things i learned when i started Drupal. This approach will work with any other theme as well.
This will keep you very much in control of what templates you want to use in different scenarios. You don't want to have too many conditional statements in one template as it becomes difficult to manage.
Using this approach you are taking advantage of the PHPtemplate engine that allows you to override templates.
Have fun and try and test it with content types, separate admin template etc.

KIntheHouse’s picture

I was having the same issue developing a subtheme with zen. Your solution worked like a charm! Thank you, thank you & thank you. :-)

tech | tech | food

jmary’s picture

In the the template.php of the subtheme add something like :

function zen_progression_preprocess_page(&$vars, $hook) {
	
    if ($vars['is_front']) {
  	$css = drupal_add_css(drupal_get_path('theme', 'zen_SUBTHEME').'/page-front.css', 'theme', 'all');
    }
    $vars['styles'] = drupal_get_css();
}

--
Julien MARY

czchlong’s picture

hi, i have done exactly what you said. however, my front page is used, but after i login, the page-front.tpl.php template is still being used..how do i get it to use page.tpl.php after logging in?

thanks

davidhernandez’s picture

See this - http://drupal.org/node/321845

You have to have a page.tpl.php for the page-front.tpl.php to work. I was having a similar problem of page-front not being used. Adding page.tpl.php to my sub-theme made it work.

byronveale’s picture

Anyone else having this problem, this solution worked for me, and is a lot simpler/cleaner/more "proper" etc. than the first suggestion -- not to knock it, evidently that worked too, but now I won't fear my Zen theme breaking on a future update...

Whoops, and evidently we noobs need to read the documentation more closely! (We weren't the first to have this problem.)

omcateer’s picture

I've also been tripped up by this before.
Do you think this is a bug of Drupal theme system? If it can't find page.tpl.php in a sub-theme surely it should fall back to the parent's page.tpl.php Is that not the point of having sub and parent themes?

hvan021’s picture

I'm using Drupal 7 and zen-7.x-3.x-dev, in order to customise front page, together with the solution above, the front page must be named as [page--front.tpl.php] (2 dash). HTH.

aceman8’s picture

Hi hvan021,

Thanks for that solution that was the easiest and worked like a charm

mareks’s picture

I believe, Clear cache is also needed.

tuben’s picture

I tried to clear the cache it worked, but there were problems with all the menu items now uses the node/id URL and not the alias that is specified on the node and in the url_alias.

Why is this happening?

It there any other way of just clearing the theme cache and not effecting everything else?

Anonymous’s picture

It's page--front not page-front: now it works!!!

Thank you