Theme Components

The three main components of any theme are the engine, the templates, and the CSS style sheet. The theme engine receives requests from Drupal to translate pure content into themed output and directs these requests to the appropriate template, which then does the translation into HTML. The style sheet then gives the HTML its look and feel.

The theme engine also has the role of managing any theme-specific settings that core Drupal is unaware of. You can see these settings by selecting administer > themes and clicking the Configure tab (admin/themes/settings). In the Toggle Display section, you'll see settings that usually include items such as the site name, site slogan, primary links, and secondary links, with the choice of turning these settings on and off.

You can see the differences between themes by comparing the list of features for the Blue-marine theme (admin/themes/settings/bluemarine) and the Chameleon theme (admin/themes/ settings/chameleon). Bluemarine has a larger set of features than Chameleon because it is based on a different theme engine, which is more fully implemented. Bluemarine is run by the PHPTemplate engine, and Chameleon has its own engine.

Templates take pure content from Drupal and decorate it with the HTML necessary for display in the site. Since a system like Drupal is rather complex, it is not generally easy, or even possible, to achieve this task without making some decisions along the way. For example, when rendering a blog post, the result will be different depending on whether the teaser view or the full view is requested. This type of decision is made in the template and is the reason why most templates require both HTML and PHP code (for the presentation logic).

Bluemarine is the name of a template that runs on the PHPTemplate engine. The files in the themes/bluemarine folder are the template files, and they depend on the engine to function. Without the files in templates/engines/phptemplate, Bluemarine would not even be recognized by Drupal as being a theme.

On the other hand, Chameleon is both a theme engine and a template at once. More accurately, when Chameleon was first written, the distinction between these two parts hadn't been as clearly delineated. Chameleon is included in Drupal mostly for historical and demonstration purposes and is known as a pure theme (meaning it handles theme calls directly in PHP without delegating them to a template or relying on an external engine). It demonstrates the essence of what a theme is and can be used and extended comfortably, but it lacks a certain flexibility, especially when it comes to reusing components across several themes.

The shortcomings of themes like Chameleon are the reason PHPTemplate was created. PHPTemplate, the theme engine, provides a comfortable and high-performance way to design theme elements that are easy to work with, modular, and reusable. It is now the standard method for theming Drupal sites, and this chapter will focus exclusively on theming with PHPTemplate.

■ Note The theme engine determines the templating language that is to be used by the theme. Engines can be written to support virtually any templating language. The standard theme engine for Drupal is PHPTemplate, Other common possibilities include Smarty, PHPTal, and XTemplate. To see which engines are available, visit http://drupal.org/project/Theme%20engines. For more information about the composition of themes, see http://drupal.org/node/11774.

0 0

Post a comment