Book Image

Drupal 6 Themes

By : Ric Shreves
Book Image

Drupal 6 Themes

By: Ric Shreves

Overview of this book

<p>Drupal is an award winning open source Content Management System (CMS). Based on PHP/MySQL, its power and flexibility combined with its exceptional design mean it is one of the most popular choices for creating a CMS website.<br /><br />Drupal employs a specialized templating system and supports themes, which allow you to change the look and feel of the system's front and back-end interfaces. <br /><br />Drupal 6 Themes is an ideal introduction to theming with Drupal 6. If you want to create a striking new look for your Drupal 6 website, this book is for you. This book is a revised, updated and expanded edition of Drupal 5 Themes, written specifically for Drupal 6. The book will show you techniques and tools to help you improve the look and feel of any Drupal 6-powered website<br /><br />Starting from the basics of theme setup and configuration, you will learn about the Drupal theming architecture and the PHPTemplate engine, and then move on to modifying existing themes and building new themes from scratch. You will find out about tools to make your theme development easier, and also find invaluable information about under-documented elements of the theming system.</p>
Table of Contents (16 chapters)
Drupal 6 Themes
Credits
About the Author
About the Reviewers
Preface

The Theme Files


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.

Screenshot of a section of the default Drupal directory structure on a server, showing the contents of the Themes directory.

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.

The Files of a PHPTemplate Theme

Let's look at the files of the default Bluemarine theme and their roles at run time:

File Name

Description

block.tpl.php

A template to define the appearance of the blocks on a page.

bluemarine.info

A key file that sets a number of parameters for your theme, including the theme's name, description, and version information.

box.tpl.php

A template used in this theme to define a specific format—a box used to frame things (like comments in the Bluemarine theme).

comment.tpl.php

A template to define the appearance of the comments that follow items.

logo.png

An image file containing the logo used in the theme.

node.tpl.php

A template to define the appearance of the nodes.

page.tpl.php

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.

screenshot.png

An image file containing a screenshot of the theme; this is used as a reference.

style-rtl.css

The alternative stylesheet for this theme, for Right-To-Left oriented text.

style.css

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.

The Files of a Pure PHP Theme

Let's look at the files that comprise the Chameleon theme and their roles at run time.

File Name

Description

background.png

An image fi le used as a page background.

chameleon.info

Sets a number of parameters associated with the theme, including the theme's name, description, and version information.

chameleon.theme

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.

common-rtl.css

An alternative stylesheet for this theme to handle Right-To-Left oriented text.

common.css

The stylesheet that covers the common Drupal elements in this theme.

logo.png

An image fi le containing the logo used in the theme.

style-rtl.css

An alternative stylesheet to set spacing in Right-To-Left orientation

style.css

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.