The themes and their respective files are kept in the directory named themes
on your server. The default distro also comes bundled with the PHPTemplate engine. The PHPTemplate files are located in a sub directory inside the themes
directory on your server.
Note
Note that although the default themes are located in the /themes
directory, if you create or install new themes, they should be placed in the /sites/all/themes
directory.
To view the theme and theme engine files in your Drupal installation, access your server and navigate to the directory located at /themes
.
The sample themes included in the distro demonstrate the two principal methods of creating themes. The themes Bluemarine, Garland, Minnelli, and Pushbutton all employ PHPTemplate. The themes Chameleon and Marvin are built without use of PHPTemplate; they are written directly in PHP. Themes that bypass the theme engine are sometimes referred to as "pure" PHP themes.
Should you use a theme engine or build a pure PHP theme? Which approach is better for you? It's hard to say; the answer varies from person to person and according to the intended use. The right answer will depend largely on your needs and your relative skill with the technologies. (Building a pure PHP theme can be a challenge for those who lack strong PHP skills!) Speaking generally, the theme engine approach is preferable as it is not only easier to master, but it is also more modular and reusable than a pure PHP approach to themes.
Let's look at the files of the default Bluemarine theme and their roles at run time:
File Name |
Description |
---|---|
|
A template to define the appearance of the blocks on a page. |
|
A key file that sets a number of parameters for your theme, including the theme's name, description, and version information. |
|
A template used in this theme to define a specific format—a box used to frame things (like comments in the Bluemarine theme). |
|
A template to define the appearance of the comments that follow items. |
|
An image file containing the logo used in the theme. |
|
A template to define the appearance of the nodes. |
|
This template is the primary theme file; it is required by PHPTemplate theme and typically defines the appearance of most of the areas on any given page. |
|
An image file containing a screenshot of the theme; this is used as a reference. |
|
The alternative stylesheet for this theme, for Right-To-Left oriented text. |
|
The primary stylesheet for this theme. |
Note that not all of these files are necessary for a PHPTemplate theme to function properly. The three key files are page.tpl.php, style.css
, and bluemarine.info
.
Note
While it is not necessary for the theme to function, it is best practice to always include screenshot.png
, as this file is used in the admin interface to provide site administrators with a preview of the installed themes. The guidelines for screenshots can be found at http://drupal.org/node/11637
The file page.tpl.php
does the heavy lifting in all PHPTemplate themes. The file incorporates, by reference, any theme-specific overrides contained in related files. In the case of the Bluemarine theme, those additional overrides are:
block.tpl.php
box.tpl.php
comment.tpl.php
node.tpl.php
Overrides are not required—the overrides in the Bluemarine theme represent a decision made by the author of the theme to style specific elements. As this is within the discretion of the theme developer, the presence and extent of overrides will vary from theme to theme.
The PHPTemplate-specific files all follow the same naming convention *.tpl.php
. The prefix of each of those files is specific in that they are intended to override functions defined elsewhere. For the system to recognize that these files in the theme directory are intended to override the originals, the names must be consistent with the originals. The naming of some of the other theme files is flexible and within the discretion of the author.
We will take an in-depth look at the various PHPTemplate files and the concepts and rules relating to overrides in later chapters.
Let's look at the files that comprise the Chameleon theme and their roles at run time.
File Name |
Description |
---|---|
|
An image fi le used as a page background. |
|
Sets a number of parameters associated with the theme, including the theme's name, description, and version information. |
|
This is the primary theme file. This is the only required file in a pure PHP theme and it defines the appearance of the page. |
|
An alternative stylesheet for this theme to handle Right-To-Left oriented text. |
|
The stylesheet that covers the common Drupal elements in this theme. |
|
An image fi le containing the logo used in the theme. |
|
An alternative stylesheet to set spacing in Right-To-Left orientation |
|
The stylesheet that covers the theme-specifi c elements in this theme. |
In this theme, the key files are chameleon.theme, common.css, style.css
, and chameleon.info
. The *.theme
file uses PHP statements to manage the page elements. The *.css
files contain the styles necessary to support the presentation of those elements.
We will examine pure PHP themes in more detail in later chapters.