In Drupal 6, to support a front page theme template, we had:

  if (drupal_is_front_page()) {
    $suggestions[] = 'page-front';
  }

inside template_preprocess_page(), allowing us to use page-front.tpl.php for a filename. In Drupal 7, this has been moved to template_page_suggestions(), which uses the following code instead:

  if (drupal_is_front_page()) {
    $suggestions[] = $suggestion . '-front';
  }

$suggestion, here, is pre-built from the values of arg(). arg() always has a value. The end result is that, in a default install of Drupal, where site_frontpage defaults to 'node', arg() returns 'node'. This 'node' gets stored in $suggestion. Thus, in a default install of Drupal, there is no 'page-front.tpl.php', only 'page-node-front.tpl.php'.

This is problematic: since the $suggestion is always based on arg(), it means that that filename for the "front page of the theme" will always be different, depending on the value of site_frontpage. Once a custom theme has been made with a front page template, one would have to be very careful about changing site_frontpage to any other value (besides a node), since it would cause the theme filename to change (i.e., change site_frontpage to /whee, which is a menu callback in whee.module, and the front page filename becomes 'page-whee-front.tpl.php'.)

Setting as critical since it a) changes (good) behavior from earlier versions of Drupal, b) makes it impossible to have a "standard" filename for the front page template, c) makes it nearly impossible for shipped themes to ship a front page template without writing their own suggestion code.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JohnAlbin’s picture

Status: Active » Needs review
FileSize
909 bytes

This should do the trick.

JohnAlbin’s picture

FileSize
1.02 KB

In IRC, Morbus gave me a comment line to add to the patch to help explain $suggestion vs. $prefix.

Morbus Iff’s picture

Status: Needs review » Reviewed & tested by the community
jensimmons’s picture

+1 Fix this bug! :) We *need* page-front.tpl.php......

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Oops. :\

IMO we should write some tests for this so we never break this again.

mr.baileys’s picture

mr.baileys’s picture

Status: Needs work » Needs review
FileSize
1.19 KB

Rerolled to keep up with HEAD.

naxoc’s picture

FileSize
2.12 KB

Added a test.

Frando’s picture

+++ modules/simpletest/tests/theme.test
@@ -39,6 +39,21 @@ class TemplateUnitTest extends DrupalWebTestCase {
+    // Set $_GET['q'] to node because theme_get_suggestions() will query it to
+    // see if we are on the front page.
+    $_GET['q'] = 'node';

I think this should use variable_get('site_frontpage', 'node').

+++ modules/simpletest/tests/theme.test
@@ -39,6 +39,21 @@ class TemplateUnitTest extends DrupalWebTestCase {
+    $this->assertEqual($suggestions, array('page__node', 'page__front'), t('Front page template was suggested.'));

I think we should just check whether page__front is in the $suggestions array, otherwise the test needs to be updated whenever a new suggestion is added, which is not what we want, I guess.

Powered by Dreditor.

Frando’s picture

Status: Needs review » Needs work
cha0s’s picture

Status: Needs work » Needs review
FileSize
2.03 KB

Updated.

naxoc’s picture

FileSize
2.15 KB

Found an error in the phpdoc comment and updated the use of variable_get to be used as the argument for theme_get_suggestions too.

cha0s’s picture

Good call. Test bot, we choose YOU!!

yoroy’s picture

Duplicated page.tpl.php in core Garland, renamed to page-front.tpl.php and added some html that made it different from page.tpl.php. Cleared cached but not seeing anything different on /node.

To be sure, I set the front page to be node/1, but no changes visible there either.

*edit* To be really sure I duplicated/renamed Stark and put that into sites/all/themes. Added page.tpl.php and added some blabla. Empty cache: blabla shown. Added a page-front.tpl.php with added yadda-yadda. Still blabla was shown on front page.

cha0s’s picture

Status: Needs review » Needs work

In addition to fixing this we need to figure out why the tests pass if it's still broken, and fix the tests...

naxoc’s picture

I can't get node-article.tpl.php tpl be found either. The suggestions are added OK - and that is why no tests fail, but they are not actually used. I suspect the drupal_find_theme_templates function is getting something wrong, but I am not at all sure.

But I am pretty sure that no suggested templates will be used as it is right now. Looking into it.

cha0s’s picture

I'm assuming we can install (hidden) themes using simpletest? If so, we should consider adding themes to *actually* fail currently, until we can track down and fix the root cause. If no one jumps on that I'll get it rolling.

The theme's templates will have some kind of key in them 'Testing page-front.tpl.php' and then visiting those pages through SimpleTest programatically should cause that text to be found.

catch’s picture

Status: Needs work » Postponed (maintainer needs more info)

Suggestions are now page--front.tpl.php and node--article.tpl.php, can't find the issue of hand. Please confirm those work, if this hasn't been added to the theme upgrade guide yet, we should bump that issue since i'm sure more people will get caught out by this.

catch’s picture

Status: Postponed (maintainer needs more info) » Needs review

Hmm wrong status, patch looks valid, but please test with the double dash.

yoroy’s picture

Status: Needs review » Reviewed & tested by the community

Latest patch works:

page--front.tpl.php

The change is documented: http://drupal.org/update/theme/6/7#template_files_double_hyphen

cha0s’s picture

Schweet!

effulgentsia’s picture

Title: page-front.tpl.php no longer works » theme_get_suggestions() fails to return 'page__front' suggestion on front page

Patch looks great.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Great work, folks! So wonderful too to see our testing framework expanded to cover some theme stuff.

Committed to HEAD, with a minor comment tweak to get the PHPDoc above testXX to be one line.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.