Building a new theme for Drupal 7

Even though the theme structure has not changed appreciably from Drupal 6, Drupal version 7 comes with a new theme implementation methodology.

This small article shows how to create a new Drupal 7 theme from scratch.

The objective of a Drupal theme is to separate the processing logic of the framework from the design element. For this, Drupal employs a complex theme system that consists of themes, theme engines, and hooks. The theme components work together with the Drupal core systems and modules design elements to create the distinctive look and feel of the user interface

drupal core architecture

DRUPAL CORE ARCHITECTURE

Planning the theme

The theme is made up of several files. Just how many files depends on the complexity of the theme. A theme can have just three files or several dozen, including graphic elements and various scripts placed in several folders within the theme directory. Figure below shows the typical file descriptions (color, images, logo, templates, stylesheets, and PHP files) that you can expect to find within a theme’s main folder.

theme-drupal3

The .info file

The .info file is a required file: It must be included for Drupal to see your theme. The .info files tells Drupal the internal name of the theme. My file is called mickey.info for sample theme called Mickey.

theme-drupal

 

The .tpl.php template files

The theme directory contains several template files with names such as xxx.tpl.php. These are template files that contain the Extensible HTML (XHTML) markup and PHP variables for the theme.

theme-drupal2

 

The template.php file

The template.php file typically holds all the conditional logic and data processing for the output of a theme. You can also use the template.php file to keep the .tpl.php files for the theme uncluttered. Because this is a PHP file, it’s mandatory to start the content with a PHP opening <?php tag, but you can omit the closing tag.

Other files

Several other elements are not required for the theme to function but might appear in many themes. These elements include the logo and screen capture, the theme-settings.php file, and color.inc files …

The logo and screen capture. These elements are recommended but not absolutely necessary for the theme to function. For simple theme Mickey theme that is what we obtain :

theme-drupal-screenshot

Conclusion

This article gave you an overview of how the theme system functions in Drupal 7. It explained the various components of a Drupal theme and how to proceed with the construction of a new theme from scratch using the default PHPTemplate theme engine.

 

 

 

extradrmtech

Since 20 years I work on Database Architecture and data migration protocols. I am also a consultant in Web content management solutions. I am an experienced web-developer with over 10 years developing PHP/MySQL, C#, VB.Net applications ranging from simple web sites to extensive web-based business applications. When not writing code, I like to dance salsa and swing and have fun with my little family.

You may also like...