Looking into Drupal theme .info files

Looking into Drupal theme .info files

Last week, I wrote about getting familiar with Drupal themes and how they are set up. This week’s post is going to be all about the .info files in Drupal themes.

The .info files are a crucial part of Drupal themes. The .info file in a Drupal theme configures the theme. Let’s look at an example of what you might find in an .info file:

name = Garland
description = Tableless, recolorable, multi-column, fluid width theme (default).
version = VERSION
core = 6.x
engine = phptemplate
stylesheets[all][] = style.css
stylesheets[print][] = print.css

The .info file contains the theme information and also the files associated with the theme. For example, you can see style.css and print.css listed above.

Another cool thing you can do with embedding stylesheets in the .info file is that you can set CSS media queries in the .info file. All you need to do is, instead of having stylesheets[all][], have something like stylesheets[screen and (max-width: 480px)][].

There are some required information that needs to be in every Drupal .info file:

  • name – This is the human-friendly name that will be displayed on the theme select page.
  • description (recommended) – This is a short description of the theme that helps identifying it on the theme select page.
  • core – Each .info file should state which major core version of Drupal it is compatible with to avoid compatibility issues.
  • engine – This is the Drupal theme engine, and it is usually phptemplate. In Drupal 7, you don’t need to have this line.

Regions

In Drupal, there are these things called block regions, which are kind of like WordPress dynamic sidebars. Block regions are dynamic content areas that could hold different content (block) that you can set through the Drupal administrator dashboard. The important thing is, these regions are set in the .info file of a Drupal theme.

regions[left] = Left sidebar
regions[right] = Right sidebar
regions[content] = Content
regions[header] = Header
regions[footer] = Footer

The above is a list of default regions in Drupal 6. To use those regions in the theme’s page.tpl.php file, all you need to do is something similar to this:

/* Display blocks in "Left sidebar" */
<?php print $left; ?>

Conclusion

Drupal theme development can seem complicated at first, but learning about Drupal themes in general and learning about what each file does can help set you on the right direction to becoming a Drupal developer.

By: Blueprint