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)

Populating a Drupal theme with dynamic content (Advanced)


Before moving further, you should be aware of the meanings of Drupal variables, which are mentioned in the following section:

  • A raw HTML file contains static content and using raw HTML in Drupal CMS is of no use since the powerful features of Drupal will be unexplored. To harness the powers of any CMS, the static content of HTML should be populated dynamically. Populating the content dynamically means that if the content is entered from the Admin panel, it should be reflected at the frontend.

  • As mentioned earlier, the garland theme is taken as the base theme to explain things here.

  • The user can also explore other default themes once he has exposure to the garland theme.

  • The user can rename the theme as per his choice. Whatever may be the name of the theme, the garland theme's structure will be used and the content of the theme files will be changed as per the requirement.

  • In the following section we will explain how to populate the Drupal theme with dynamic content, test to ensure if things are moving in the right direction, and enable the theme for testing.

How to do it...

The screenshot of the Garland theme being used as the base theme to implement instructions mentioned in this book is given in this section. Everything that will be instructed should be implemented in the PHP files of the garland theme.

If any other file (for example, a CSS or JavaScript file) is required to be used at any point in time, it will be mentioned specifically.

Note

Please remember, we will use files having the .php extension to populate the Drupal theme with dynamic variables. Names of the files must be intact, while the content can be changed with your HTML.

Everything we discussed until now about the garland theme is of no use if we don't know the location of the garland theme, isn't it ? How will you locate the garland theme? The following screenshot depicts the code structure of Drupal. Click on the themes folder highlighted in yellow:

You will be able to see the garland folder, as shown in the following screenshot:

The following screenshot depicts the code structure of the garland theme:

  1. Perform the following steps to populate raw HTML with Drupal variables:

    1. Create a backup of all the files.

    2. Open a PHP file.

    3. Paste the HTML content onto the file.

    4. Replace the static text with the concerned Drupal variable.

  2. Suppose a raw HTML file is having static content as given in the following code, the static content in the head and title tags will be displayed using a Drupal variable as mentioned in the preceding section using the code [$title] tag of Drupal.

    [<HTML>
      <head>Our Drupal website</head>
    <title>Title of the website</title>
    <body>Content of the website</body>
    </HTML>
    ]
  3. After using the Drupal variable in our code, it should look as follows:

    Code [
    <HTML>
      <head><?php print $druapl_variable ?></head>
    <title><?php print $druapl_variable ?></title>
    <body><?php print $druapl_variable ?></body>
    </HTML>
    ]

A list of theme variables can be found in the garland theme and other themes.

After populating the Drupal theme with dynamic variables, we need to test if things are working properly or not. Before that, we need to check if the garland theme is enabled or not. If it isn't enabled, we need to enable it

We need to perform the following steps to enable the garland theme (assuming Drupal 7 is installed on the user's machine):

  1. Log in to the Drupal 7 Admin panel.

  2. Enable the Garland theme if it is not enabled. Follow steps 3 and 4 to enable the Garland theme.

  3. Click on Appearance (highlighted in yellow in the following screenshot) on the top menu bar to view a list of themes:

  4. If the Garland theme is disabled, it will be displayed in the Disabled Themes section. Click on the Enable link to activate the Drupal theme as shown in the following screenshot:

  5. Once enabled, Garland will appear in the Enabled Themes section with a message displayed as shown in the following screenshot:

Now we are in a state where we can test if things are working properly or not. We will add content from Drupal's Admin panel and it should be reflected at the frontend.

We need to perform the following steps to add content:

  1. Navigate to Add content by clicking on the Content tab as shown in the following screenshot:

  2. Click on the Article link as shown in the following screenshot:

  3. If the previous step is successfully executed, the page shown in the following screenshot will be opened. Enter Title and Body and save it.

    Check at the frontend. The content added by the user should be reflected at the frontend.