2

I'm writing a new Drupal theme. I have a html.tpl.php and a page.tpl.php (soon to add a set of node.tpl.php's for each different content type). I want my page.tpl.php to be used for every page, including the front page — every page is going to have exactly the same layout, so I don't need a page-front.tpl.php.

When I visit www.example.com/node/whatever, my page.tpl.php is applied.

When I visit www.example.com (the front page), my page.tpl.php is completely ignored — I'm assuming that Drupal is looking for page--front.tpl.php, not finding it, and then ignoring my page.tpl.php.

How do I get Drupal to use my themes page.tpl.php template for the front page?

edit:

Apparently my front page isn't even being counted as a node?!? The below code will die on any page except for the front page:

function cefmap_preprocess_page(&$vars, $hook) {
    if (isset($vars['node'])) {
        die;
    }
}

How do I get my front page to be treated as a node like any other node?

edit:

Think I've worked this out, and it's really dumb of me. I set that node to "be the front page" through structure, menus, main menu and then set the path for the link to be "<front>".

Of course, that just changes the link in the menu to be "/", without changing the actual path of the node. So I don't actually have a node at "/", and so I don't get to have a page template or a node template applied.

3

It is page--front.tpl.php - note the double dashes.

The cascading matches my understanding. page.tpl.php should be called if there are no higher priority page templates. You need devel themer to work this out http://drupal.org/project/devel_themer. It will print out on the screen the template matches.

Details are in the drupal theming guide. in this section:

page--[front|internal/path].tpl.php 
base template: page.tpl.php
  • Thanks for the info - I'm currently fiddling with devel_themer to get it to show what template's it's looking for - I see the "themer info" box on my admin pages (Seven theme), but not under my new theme - so I'm assuming that I'm not printing some html.tpl.php variable that I need to to get it to show up. Is there any other way to get info on what templates Drupal is looking for, and why it's not rendering my front page with my page.tpl.php? – George Mar 15 '13 at 4:58
  • Is your new theme a sub-theme from a known theme? What is it based on? – Interlated Mar 15 '13 at 6:08
  • Hi @Interlated: not a subtheme, but I've solved the problem - PEBKAC as usual. ;) See my edit above, or I submitted the solution as an answer for the next person who might see this. Thanks for helping. – George Mar 15 '13 at 6:13
  • Cool. It is a nice practice to subtheme and only custom what you have to. Looks like it wouldn't have made a difference. – Interlated Mar 15 '13 at 6:29
2

You can put this code into your template.php:

function yourtheme_preprocess_page(&$vars) {
 $vars['theme_hook_suggestions'][] = "page";
}

If you really want to use page.tpl.php for all

1

Hi i think drupal will take the page.tpl.php with out any code.

Look at the bartik theme structure. Here page.tpl.php is used in front page also.

bartik

1

page--front.tpl.php for the theming the front page and page--node.tpl.php for rest of the pages

0

This was pretty dumb: I set that node to "be the front page" through structure, menus, main menu and then set the path for the link to be "".

Of course, that just changes the link in the menu to be "/", without changing the actual path of the node. So I don't actually have a node at "/", and so I don't get to have a page template or a node template applied when I visit "/".

The proper way to set the front page is to go to configure, site information and then set the "default front page" there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.