This bit is extremely crucial to someone like me who is more or less new to Drupal.

page-node-x.tpl.php
page-node.tpl.php
page-front.tpl.php
page.tpl.php

I have seen similar hierarchies mentioned elsewhere.

Now, isn't there a central repository of template hierarchies or something? I couldn't find it in the handbooks for sure.

Subir

Comments

josesanmartin’s picture

---

José San Martin
http://www.chuva-inc.com/

dan33’s picture

The person who replied above me is wrong. Here are the template files used:

For pages:

Example: http://www.example.com/node/1/edit

page-node-edit.tpl.php
page-node-1.tpl.php
page-node.tpl.php
page.tpl.php

Example: Your home page.

page-front.tpl.php
page.tpl.php

For nodes:

node-type.tpl.php
node.tpl.php

For comments:

comment.tpl.php

For blocks:

block-module-delta.tpl.php
block-module.tpl.php
block-region.tpl.php
block.tpl.php

For boxes:

box.tpl.php

When determining which template file to use, it'll start from the top and work its way down. So, for example, if node-type.tpl.php file doesn't exist, it'll use node.tpl.php. For a better look as to how templates work, take a look at the phptemplate.engine file in your themes/engines/phptemplate folder. Hope that helps.

subir_ghosh’s picture

Thanks for the elaborate reply Dan.

It gives me so much of a headstart :)

-----------------------------
Subir Ghosh
www.subirghosh.in

subir_ghosh’s picture

There's some more:

Taxonomy:
page-vocabularyname-termname1-termname2.tpl.php
page-vocabularyname-termname1.tpl.php
page-vocabularyname.tpl.php

Admin:
page-admin.tpl.php

Login:
page-login.tpl.php

-----------------------------
Subir Ghosh
www.subirghosh.in

subir_ghosh’s picture

[Duplicate]

-----------------------------
Subir Ghosh
www.subirghosh.in

ghmercado’s picture

are these hierarchies on the handbooks? or on the main howto sections?

'cause dang, I spent a whole day trying to figure this out and BAM here it all is.

dvessel’s picture

FYI, all the template naming suggestions are set from phptemplate.engine. Peek in that file and look for phptemplate_HOOK. In Drupal 5, there's a callback function that accepts templates for the last parameter.

Once you understand what it's doing, you can go a lot further and change it to your liking with _phptemplate_variables() by passing $vars['template_files'] with an array of your own suggestions.

http://api.drupal.org/api/function/_phptemplate_callback/5

subir_ghosh’s picture

I have created a new content type called "indicators" and also created "page-indicators.tpl.php" for the purpose.

However, the page itself is showing the default page.tpl.php.

I tried to add something to template.php, but it doesn't work:

function wildlifewatch_indicators($hook) {
  if ($hook == 'page') {
  return _phptemplate_callback('page-indicators', array('type' =>
$indicators));
}

Even this did not work:

function _phptemplate_variables($hook, $vars) {
  if (($hook == 'page' || $hook == 'node') && isset($vars['node']) {
    $vars['template_files'][] = $hook .'indicators'. $vars['node']->indicators;
  }

  return $vars;
}

I used this to replace some other previous code in template.php:

function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    // Send a new variable, $has_terms, to see wether the current node has any terms
    case 'node':   
      if(count(taxonomy_node_get_terms($vars['node']->nid)))
        $vars['has_terms'] = TRUE;
      else
        $vars['has_terms'] = FALSE;
  }
  
  return $vars;
}

-----------------------------
Subir Ghosh
www.subirghosh.in

dvessel’s picture

You were close on your second bit:

function _phptemplate_variables($hook, $vars) {
  if ($hook == 'page' && !empty($vars['node']->type)) {
    $vars['template_files'][] = 'page-node-'. $vars['node']->type;
  }

  return $vars;
}

After that "page-node-indicators.tpl.php" will work. "node-indicators.tpl.php" (for node templates) is automatically checked since it's built-in so no need to add that.

joachim’s picture

I think all of what the poster above mentions is on this handbook page: http://drupal.org/node/104316
If there's stuff missing, post a comment on the handbook page or file a documentation issue.

I think that page could probably do with being moved to it sits under the page on Page.tpl.php. More chance of people finding it then.

emmadibley’s picture

Hi,

Does anyone know the TPL Hierarchy for "Create new account page" "Log in page" and "Request new password page"?
I really want to customize these pages and I cant seem to get them to work.

(working with Drupal v5 and v6)

Thanks,
Emma

chesire1984’s picture

"create new account page": page-user-register.tpl.php

"Log in page": page-user.tpl.php

"Request new password page": page-user-password.tpl.php

best,

steel-track’s picture

The login page would actually be "page-user-login.tpl.php". Using page-user.tpl.php will overwrite all user pages.

The list is then:

"create new account page": page-user-register.tpl.php

"Log in page": page-user-login.tpl.php

"Request new password page": page-user-password.tpl.php

socialnicheguru’s picture

i really needed this

http://SocialNicheGuru.com
Delivering inSITE(TM), we empower you to deliver the right product and the right message to the right NICHE at the right time across all product, marketing, and sales channels.

ajlowndes’s picture

all these (other) posts seem to ask me to create or edit my template.tpl.php, and put into it (for instance) a php function. Only my theme doesn't have a template.tpl.php. If I create one, will it be called before page.tpl.php and the rest? Or is template.tpl.php only for functions? If so, why isn't it simply called "functions.tpl.php"?

ajlowndes’s picture

whoops, actually these posts (such as http://drupal.org/node/350634) ask me to create or edit template.php, not template.tpl.php. But it (and others) do ask me to create or edit it in my theme folder. so it is a theme file, but does it just hold functions, or what?

ajlowndes’s picture

yes, it holds functions and some other stuff. Anatomy of a Drupal 6 theme http://drupal.org/node/171194 for anyone interested.