Book Image

Instant Premium Drupal Themes

By : Pankaj Sharma
Book Image

Instant Premium Drupal Themes

By: Pankaj Sharma

Overview of this book

Drupal’s theme layer, and the themes that use it, are responsible for the look and feel of a Drupal web site. Themes have the final say and ultimate control over almost every aspect of each page. Good themes consist of all the same elements that you would find on any reputable web site, including standards-compliant XHTML markup, CSS, and JavaScript. How it all comes together is what is so special and what makes Drupal themes so flexible and powerful. Premium Drupal Themes is a practical, hands-on guide filled with clear, step-by-step examples which shows you how to create Drupal themes using HTML. This book will show you the best practices and conventions that you should adopt and utilize so you can change the way Drupal looks using HTML without wasting energy digging through Drupal’s code. Starting with the essentials including Drupal terminology and Drupal theme structures, this book will show you how to configure raw HTML in a Drupal environment. You will learn about the Drupal template variables and also how to populate a Drupal theme with dynamic content. You will also discover how to customize the search result page and how to add regions to your home page. This book will help you familiarize yourself with the theme engines and will help you learn about the core of Drupal’s theme rendering system. Finally, you will learn how to create your very own Drupal theme that will take people’s breath away!
Table of Contents (7 chapters)

Understanding Drupal's theme structure (Simple)


The Drupal theme is located in the themes folder in the root. Drupal provides some themes by default such as bartik, garland, seven, and stark.

These themes can be used as a skeleton to create your own theme.

We will use the Garland theme as the base theme to explain Drupal in this book.

Garland's templates will be used as the base.

Any Drupal theme consists of the files mentioned in the Getting ready section. These files are needed to create any Drupal theme.

Getting ready

A list of the Drupal theme files and a brief description of their functionalities are discussed in this section.

While creating a Drupal theme, knowledge of each theme file is mandatory. The name of a theme file should not be changed at any cost. Drupal does not understand any other file except its own theme file.

Template name

Template function

theme-name.info

This is the gateway of Drupal themes. This file contains information about the theme's name, its version, and its description. Other than this, the theme skeleton is also mentioned here.CSS files are also configured in this file.

comment.tpl.php

Comments inside the content are taken care of by this file.

style.css

CSS of the site is placed here. Apart from style.css, other CSS files can also be used, such as fix-ie.css, fix-ie-rtl.css (to address browser compatibility issues) and print.css.

page.tpl.php

This is the main file of the Drupal theme. The Drupal theme revolves around this file. This is pivotal for the development of the Drupal theme.

node.tpl.php

This file is responsible for the content of the Drupal node. You can say that the node is governed from here.

logo.png

It is optional but it is advised to have this file, since it is according to Drupal conventions and it provides a face to the theme.

screenshot.png

A screenshot of your theme is represented by an image and it helps you to recognize your theme in the Admin panel.

template.php

In this file we can write our own theme function. It is advisable to write theme specific functions here. We should not try to hack the Drupal core as it might disrupt Drupal as a whole.

theme-settings.php

Theme settings and global variables can be defined here.

maintenance-page.tpl

As the name suggests, this page is displayed when the site is down for maintenance. It's optional, but recommended.

region.tpl.php

This template is used to display a region in the Drupal theme.

block.tpl.php

This template is used to display blocks in the Drupal theme.

README.txt

This file can be used to provide instructions to users.

html.tpl.php

This file is used to display the basic HTML structure of a single Drupal page.

How to do it...

We need to perform the following steps:

  1. Download the latest version of Drupal from https://drupal.org/download

  2. Install Drupal (follow the instructions to install Drupal at https://drupal.org/documentation/install)

  3. Supposing your installation name is drupal, go to garland in the themes folder.

  4. You can find all the necessary Drupal templates at drupal\themes\garlandpath.

There's more...

Drupal 7 provides listed themes. By and large, all themes contain the above mentioned template files with different directory structures.

The structures of the following default themes can be copied and used to create your own Drupal theme:

  • Bartik

  • Garland

  • Seven

  • Stark