Phone: (Australian callers) 02-8003-4624
(international callers) +61-2-8003-4624
Drupal theming for designers, continued.
Drupal Theming – Part 2 – Controlling themes
This is a continuation of the earlier article on Drupal theming for designers.
Near the end of the previous article, we mentioned other *.tpl.php files used by themes. These files, and any others that you create, using Drupal’s PHPTemplate file naming convention, you are able to ‘override’ the default display:
Drupal’s PHPTemplate theme engine uses the content generated by these files in page.tpl.php, as the following diagram demonstrates:
More control means more power
Using the *.tpl.php you can control:
- the display of different content types, such as blogs, forum posts, or anything else you create. What are 'content types' (node-[content type].tpl.php)
- the display of content in edit-mode (node-edit.tpl.php)
- the display of individual nodesWhat is a 'node' (node-[node ID number].tpl.php)
- the display of the front page
Controlling the content being passed to the *.tpl.php using variables
Let’s look at the variables used in page.tpl.php and node.tpl.php:
Here, we see page.tpl.php prints variables such as $sidebar_left and $mission.
In node.tpl.php we see variables such as $sticky.
You can use template.php to override functions returning these variables and you can intercept other variables:
This template.php example, from the Zen theme, demonstrates function overrides:
Here is the documentation listing all themable functions: http://api.drupal.org/api/group/themeable/5
It also demonstrates variable re-definition, which is scope controlled: