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

---
---
The person who replied above
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
Thanks for the elaborate reply Dan.
It gives me so much of a headstart :)
More
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
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
are these hierarchies on the
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
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
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
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
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
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
"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
i really needed this