Using different page templates depending on the current path
In Drupal 5.0, PHPTemplate supports the use of multiple page templates for a single theme. Depending on the current url path (node/1, taxonomy/term/2, or user/1, for example), PHPTemplate will search for multiple templates before falling back on the default page.tpl.php file.
For example, if you were to visit http://www.example.com/node/1/edit, PHPtemplate would look for the following templates, in descending order:
page-node-edit.tpl.php
page-node-1.tpl.php
page-node.tpl.php
page.tpl.php
If you were to visit http://www.example.com/tracker, PHPTemplate would look for the following templates:
page-tracker.tpl.php
page.tpl.php
This rule also works for URLs for things like users and taxonomy. When visiting http://www.example.com/user/1, PHPTemplate looks for the following template files in this order:
page-user-1.tpl.php
page-user.tpl.php
page.tpl.php
Note that the front page is a special case (that is the URL is http://example.com with no path following.) In this case you can use a special template:
page-front.tpl.php
Remember that these template suggestions are based on the default drupal path for a particular page. If you've used the path or pathauto module to hide them with url aliases, these templates will still be searched based on the original paths.
If you need to switch page template files based on some other rule (the role of the logged in user, for example), implement the phptemplate_variables() function in your theme's template.php file. The $vars['template_files'] variable should store an array of possible tpl.php files, with the first one to check listed last.

Creating a Blank Page Content Type
I have a need to create pages on my website that only contain the HTML entered in the Body field of the page. Because using mod_rewrite (in Apache) causes Drupal to serve all requests to {mysite.com}/anything, I needed a way to create static HTML pages that emulates the old way (similar to uploading testfile.html to /home/my_user/public_html). This method provides that capability.
<?phpif ($node->type == "blank_page" && arg(2) != "edit") {
print $node->body;
return;
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
[1]If you use the Pathauto module, you could set the pattern for the blank_page content type to use the title in it. That way you're not completely wasting the title field. You could use something like this: [title-raw].html
Thanks!
Josh
P.S. I am very new to Drupal, so use this code at your own risk. Please let me know if you have a better way of accomplishing this task.
Note that you can still
Note that you can still upload an HTML file the old way using FTP or whatever - Drupal will only handle a request if the request doesn't resolve to an existing file.
Still a useful tip though :-)
gpk
----
www.alexoria.co.uk
but php snipets don't seem to work this way?
This a great tip - but I wasn't able to get php to work (for instance, adding a login form, or showing the $tabs).
So instead I tried printing $content like this
<?phpif ($node->type == "splash" && arg(2) != "edit") {
print($content);
return;
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
This way it still prints the body, and it prints the php snippets (though oddly it didn't print the $tabs, which I inluded in my html the same way it shows in the page template). This way also places the html head within a node div (unlike your example to
print $node->body), which is not ideal.Is there a better way to do modify your code to allow php snippets? or am I missing something?
Thanks!
Scott
Theming nodes by content type
Here the page for Theming nodes by content type.
Issue with Drupal 6.1?
Is there an issue with this page templates using path/url alias with drupal 6.1? It's strange because I can make a custom template for Administration pages (page-admin.tpl.php) and although it worked for user-created pages like About Us page (using page-node-1.tpl.php), it won't on path/url aliases like page-about.tpl.php . Even with theme developer, it reports Candidate template files: page-node-3.tpl.php < page-node.tpl.php < page.tpl.php and do not include URL/path alias. Did I miss something? Thanks
I don't think different page
I don't think different page templates per URL alias are supported out-of-the-box in any version. See e.g. http://drupal.org/node/139766. In 6.x I think you have to use the "preprocess" thing instead of _phptemplate_variables() ...
gpk
----
www.alexoria.co.uk