Book Image

Drupal 7 Theming Cookbook

By : Karthik Kumar
Book Image

Drupal 7 Theming Cookbook

By: Karthik Kumar

Overview of this book

<p>The greatest strength of Drupal lies in its design which, when employed correctly, allows developers to literally handcraft every aspect of a site, so that it looks and performs exactly how they want it to. While it is reasonably straightforward to download a Drupal theme and install it, doing anything beyond that is not. Using custom themes requires familiarity and experience with Drupal's theming system, especially if you want to easily administer and maintain your themes.</p> <p>Drupal 7 Theming Cookbook provides a plethora of recipes that enable Drupal template designers to make full use of its extensibility and style their site just the way they want it. It is a well-rounded guide which will allow users to take full advantage of Drupal's theming system.</p> <p>This cookbook starts with recipes which address the basics of Drupal's theme system, including regions and blocks. It then moves on to advanced topics such as creating a custom theme and using it to modify the layout and style of content. With the introduction of the Field API and the growing importance of Views and Panels in Drupal 7, chapters have been dedicated to each feature. You will also learn many techniques for dealing with Drupal&rsquo;s templating system, which will allow you create themes which surpass even the existing Drupal and contributed modules.</p>
Table of Contents (18 chapters)
Drupal 7 Theming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

Introduction


Drupal is designed to separate logic from presentation with the former usually handled through the use of modules and the latter via themes. Although this separation is not absolute, it is distinct enough to facilitate quick and efficient customization and deployment of websites. This especially holds true when the site is developed in a team environment as it enables developers, designers, and content managers to work independently of each other.

Themes are synonymous with skins in other applications and control the look and feel of a website. Each theme can consist of a variety of files ranging from a .info configuration file, which registers the theme with Drupal, to .tpl.php template files accompanied by CSS, JavaScript, and other files that determine the layout and style of the content. Depending on the nature of the site and its requirements, developers can choose from the slew of themes available on http://drupal.org as contributed themes or instead, decide to roll their own.

Contributed themes are, as the name suggests, themes that have been contributed by the Drupal community at large. They usually tend to be designs that have been developed by a user for a site and then shared with the community, or designs from other packages or sites which have been ported over to Drupal. Consequently, while they are ready-to-wear, they are generic in nature and lack uniqueness. Furthermore, the quality of these themes vary significantly from one to the other with some being excellent and others well below par. Contributed themes are an acceptable choice for sites that require rapid deployment or for hobby sites with simple needs where uniqueness is not a factor.

Custom themes, on the other hand, are a necessity for sites with unique requirements in layout, usability, and design. While they are often built from the ground up, it is now established practice to use special starter themes as a base from which they can be extended.

Contributed themes can be accessed at http://drupal.org/project/themes. This page, by default, lists all available themes and provides filters that can be used to whittle the results down based on Drupal version compatibility as well as other search terms. Additionally, sorting options can be used to rearrange contributions based on their popularity, update status, and other criteria. More information about each theme can be accessed by clicking on its Find out more link.

There are a number of considerations to keep in mind whilst choosing a contributed theme. Firstly, it is important to have a general idea of the layout required for our site with the chief concern usually revolving around the column structure of the design. Most themes support a three-column (with two sidebars and a content area) layout which can also optionally function as a two-column single sidebar layout if no content is added to one of the sidebars. The more exotic ones support four or more columns and are only really a viable option for special cases:

Secondly, while fewer themes nowadays are being laid out using tables, they are still around. Unless there is no other recourse, these should be avoided in favor of CSS layouts.

Next, check to see whether the theme is a fixed-width or a fluid theme or supports both types. Fixed-width themes, as the name suggests, maintain a predefined width irrespective of the screen resolution of the user. As a result, the site has a consistent appearance. Fluid layouts, or liquid layouts as they are sometimes referred to, grow according to the user’s screen size and consequently make better use of the available real estate. The question of which to use is generally decided on a case by case basis.

The Drupal theme system also supports the use of different theme engines to render the design. Each engine uses a different process by which the designer can interact with Drupal to implement a design. The PHPTemplate engine is built into Drupal and is by far the most popular of the ones available. The vast majority of contributed themes available are compatible with PHPTemplate. Nevertheless, it is prudent to check the specifications of the theme to ensure that it does not require a different theme engine. Contributed theme engines can, if necessary, be downloaded from http://drupal.org/project/theme+engines.

Every theme’s project page usually provides screenshots and explicitly specifies layout and other pertinent information. A number of them also link to a demonstration page, as in the following screenshot, where the theme can be previewed and tested using different browsers, screen resolutions, and so on. A third-party site http://themegarden.org, which showcases various contributed themes, comes in very handy for the same reason:

Additionally, project pages customarily link to their Git repositories where files within the theme can be viewed prior to downloading it. It is also worth exploring the issue queue of a project to see if bugs have been reported and are being addressed in a timely manner.

Note

Git is a tool used by Drupal developers to manage their code and control their releases. It is effectively a repository for modules, themes, and Drupal itself. More information on Git is available at http://drupal.org/handbook/git.

Once the list of candidate themes has been narrowed down to a short list, the only way to test them further is to download and install them. The theme project page lists available downloads based on version and stability along with release notes which might be useful to glance through as well. Download the latest release recommended for Drupal 7. The recipes in this chapter will address the installation and configuration of a downloaded contributed theme.