Drupal: Theme Templates Order
In this article we will figure out an order which is used for templates of your Drupal-based website. Read the full story to get know the details.
PHPTemplate supports using of templates for a certain system URLs.
If you are at http://example.com/node/1/edit, then templates will be found in the following sequence:
- page-node-edit.tpl.php
- page-node-1.tpl.php
- page-node.tpl.php
- page.tpl.php
If you are at http://example.com/tracker, then templates will be found in the following sequence:
- page.tpl.php
If you are at http://example.com/user/1, then templates will be found in the following sequence:
- page-user-1.tpl.php
- page-user.tpl.php
- page.tpl.php
If you are at http://example.com/taxonomy/term/1, then templates will be found in the following sequence:
- page-taxonomy-term-1.tpl.php
- page-taxonomy-term.tpl.php
- page-taxonomy.tpl.php
- page.tpl.php
If you are at http://example.com/, then templates will be found in the following sequence:
- page-front.tpl.php
- page.tpl.php
You can create templates to generate individual pages. Page templates could be based on the system URL of a page.
For example, if you are at /node/1/edit, then templates will be found in the following order:
- page-node-edit.tpl.php
- page-node-1.tpl.php
- page-node.tpl.php
- page.tpl.php
Note: templates are found on the basis of standard Drupal URL. I.e. if you have set an alternative URL manually or you use Pathauto module, templates will be found regarding their system path anyway. Alternative URLs will not be used for the search.
If you want to switch page templates following a certain rules (for example, user roles), you should specify the rules in template.php. $vars[‘template_files’] variable should define array of possible templates.
You can view an example of defining templates with this variable here:
Creating a separate admin theme.
Good luck!