Hierarchies of templates (TPL files)

newswatch - May 30, 2007 - 18:13

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

---

zsanmartin - May 31, 2007 - 01:32

---

The person who replied above

dan33 - May 30, 2007 - 19:03

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.

Thanks for the elaborate

newswatch - May 30, 2007 - 21:13

Thanks for the elaborate reply Dan.

It gives me so much of a headstart :)

More

newswatch - September 12, 2007 - 09:47

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

Some

newswatch - July 16, 2009 - 07:44

[Duplicate]

are these hierarchies on the

ghmercado - October 14, 2008 - 05:01

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.

FYI, all the template naming

dvessel - September 22, 2007 - 19:31

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

I have created a new content

newswatch - October 22, 2007 - 20:30

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;
}

You were close on your

dvessel - October 25, 2007 - 15:01

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.

I think all of what the

joachim - October 22, 2007 - 20:31

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.

Custom login pages

emmadibley - February 26, 2008 - 12:06

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

Custom Login Pages

chesire1984 - May 13, 2008 - 00:49

"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,

gret tutorial

SocialNicheGuru - June 1, 2008 - 16:28

i really needed this

where does template.tpl.php fit in?

ajlowndes - July 21, 2009 - 02:03

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"?

Eagles may soar, but weasels don't get sucked into jet engines.

whoops

ajlowndes - July 21, 2009 - 02:13

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?

Eagles may soar, but weasels don't get sucked into jet engines.

answered my own question

ajlowndes - July 21, 2009 - 02:22

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

Eagles may soar, but weasels don't get sucked into jet engines.

 
 

Drupal is a registered trademark of Dries Buytaert.