3

We are using Drupal 6. When accessing http://www.mysite.com/, the tpl file which is displayed is named page-front_page.tpl.php. I cannot figure out where the logic is which decides that page-front_page.tpl.php will be used for the front page.

I created a second file, named page-front.tpl.php, and this will display instead of page-front_page.tpl.php, seemingly bypassing page-front_page.tpl.php.

Does anybody know how page-front_page.tpl.php is defined as a front page? Or is there some sort of automatic URL parsing happening here?

Edit 1.0: Please read my comments to answers below for more information.

  • Not sure if it applies to Drupal 6 but this Stackoverflow post shows other places where theme suggestions could be specified: stackoverflow.com/questions/5194109/… – nmc Aug 15 '11 at 19:23
  • @nmc - Thanks, but it doesn't seem to apply to 6 – letseatfood Aug 15 '11 at 20:13
3

please review in /includes/theme.inc near to the line if (drupal_is_front_page()) {...

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

I changed the $suggestions[] value, and I saw that .tpl.php name to the front page can be customized.

According the comment of nmc,

this file/code should not be modified as it is part of Drupal core

. this is only to locate where can be stablished the value.

| improve this answer | |
  • In my theme.inc file, the line is $suggestions[] = 'page-front';, and that still doesn't explain why page-front_page.tpl.php is being used. Thank-you though! – letseatfood Aug 15 '11 at 19:05
  • 1
    Just to clarify, while the file naming convention may be set in includes/theme.inc in the code that moon.watcher has posted but this file/code should not be modified as it is part of Drupal core. See drupal.org/best-practices/do-not-hack-core for more details on why not to hack core. – nmc Aug 15 '11 at 19:08
  • hello nmc, yes, the question is where can be the value. and I agree about that can not be used this way. – cigotete Aug 15 '11 at 19:18
  • Hi letseatfood, review if $suggestions was overwrited in another place of theme.inc, so review more declarations using $suggestions – cigotete Aug 15 '11 at 19:34
  • @moon.watcher - Yeah, I looked for that, but there is not an override. – letseatfood Aug 15 '11 at 20:08
2

If the URL for the page that you set as front page is example.com/front_page, then one of the suggestions used by Drupal is "page-front_page"; this causes Drupal to look for "page-front_page.tpl.php."

The code that selects that suggestion is in template_preprocess_page():

  // Build a list of suggested template files in order of specificity. One
  // suggestion is made for every element of the current path, though
  // numeric elements are not carried to subsequent suggestions. For example,
  // http://www.example.com/node/1/edit would result in the following
  // suggestions:
  //
  // page-node-edit.tpl.php
  // page-node-1.tpl.php
  // page-node.tpl.php
  // page.tpl.php
  $i = 0;
  $suggestion = 'page';
  $suggestions = array();
  while ($arg = arg($i++)) {
    $arg = str_replace(array("/", "\\", "\0"), '', $arg);
    $suggestions[] = $suggestion . '-' . $arg;
    if (!is_numeric($arg)) {
      $suggestion .= '-' . $arg;
    }
  }
  if (drupal_is_front_page()) {
    $suggestions[] = 'page-front';
  }

For example.com/front_page, arg(0) returns "front_page" and the suggestion will be "page-front_page."

That suggestion comes before "page-front"; that means that in the case there is a file named "page-front_page.tpl.php" it will be used instead of "page-front.tpl.php."

| improve this answer | |
  • If both "page-front.tpl.php" and "page-front_page.tpl.php" are present, and http://example.com/front_page is accessed, then "page-front.tpl.php" is displayed. If "page-front.tpl.php" does not exist, and http://example.com/front_page is accessed, then "page-front_page.tpl.php is displayed. So, I gather that page-front.tpl.php has priority. But, if "page-front.tpl.php" is not present and I rename "page-front_page.tpl.php" to something like "page-front_example.tpl.php", then access http://example.com/front_example, a "Page Not Found" is displayed. – letseatfood Aug 16 '11 at 14:04

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.