Building Drupal 6 Theme


Published on

Theme building basics for Drupal 6.

Published in: Technology
  • Be the first to comment

Building Drupal 6 Theme

  1. 1. Building a Drupal Theme Gaurav Khambhala <> DeepRoot Linux - March 22, 2009Gaurav Khambhala <> Building a Drupal Theme
  2. 2. Introduction What is Drupal theme ? Drupal theme components Try it on your own Gaurav Khambhala <> Building a Drupal Theme
  3. 3. What is Drupal theme ? Drupal theme is a presentation layer to Drupal database. Drupal theme is a set of few files, which will work together to present the Drupal backend data. Gaurav Khambhala <> Building a Drupal Theme
  4. 4. Theme FilesFollowing are the few essential files for the drupal theme: style.css page.tpl.php block.tpl.php node.tpl.php comment.tpl.php template.php logo.pngWe will follow the instruction and create a theme as a byproduct of this presentation. Create a theme directory asnamed example. In the next couple of slides, we will look intoindividual theme files and their contents. Gaurav Khambhala <> Building a Drupal Theme
  5. 5. description A required file in drupal theme. Drupal will pick theme name from this file only It should be named as your It contains the stylesheets, javascript declarations It contains block regions for the theme If you want to define some theme level features, you can list down in this file Gaurav Khambhala <> Building a Drupal Theme
  6. 6. contentContent of the file: name* description version core* engine base theme stylesheets scripts regions php features Gaurav Khambhala <> Building a Drupal Theme
  7. 7. content name Required. A human readable name of the theme. In our case, name = Exampledescription A short description of the theme. This description is displayed on the theme select page. description = Example drupal theme version Version of the theme. version = 0.1 core Required. Version of the drupal core, your theme compatible with. core = 6.x engine The theme engine. engine = phptemplate Gaurav Khambhala <> Building a Drupal Theme
  8. 8. cont. content base theme If you are building a sub theme. It will inherit base theme settings.This field is not required right now as we are building a new theme. sub theme = garland regions Set of regions you want to enable for this theme.Machine readable values in square brackets is the key followed by regions and human readable name as a value. regions[region-name] = value Gaurav Khambhala <> Building a Drupal Theme
  9. 9. cont. content regions Following are the default regions if no regions specified. regions[left] = Left sidebar regions[right] = Right sidebar regions[content] = Content regions[header] = Header regions[footer] = Footerstylesheets Stylesheet to use for the theme. stylesheets[all][] = style.css scripts Javascript files to use for the theme. scripts[] = script.js php Minimum pHP Version this can support.Not required for most of the themes. Can omit this settings. php = 4.3.3 Gaurav Khambhala <> Building a Drupal Theme
  10. 10. cont. content features You can enable/disable features for the themes. features[] = feature-name Basically if you don’t specify anything following are the default values: features[] = logo features[] = name features[] = slogan features[] = mission features[] = node_user_picture features[] = search features[] = favicon features[] = primary_links features[] = secondary_links Gaurav Khambhala <> Building a Drupal Theme
  11. 11. cont. contentNow you have your file ready with the followingcontent:name = Exampledescription = Example drupal theme.version = VERSIONcore = 6.xengine = phptemplatestylesheets[all][] = style.cssNo need to specify regions and features. Let it be defaultvalues. Gaurav Khambhala <> Building a Drupal Theme
  12. 12. Theme is ready to useNow if you copy the example theme directory to your drupaltheme directory. Drupal 6 will detect it from .info file andready to be enabled. Go to Administer-SiteBuilding-Themes.You can see the example theme listed there.Now we will require to create style.css and php template filesto display the content as we want for this theme. Gaurav Khambhala <> Building a Drupal Theme
  13. 13. Template filespage.tpl.php A main template file that contains the display structure of almost all of the pages.node.tpl.php Defines the node content.block.tpl.php Defines block content.comment.tpl.php Defines comment content.template.php Defines comment content. Gaurav Khambhala <> Building a Drupal Theme
  14. 14. Create template files - page.tpl.phppage.tpl.php file is a combination of html tags as well asdrupal php template variables to show the requireddata.Following are some phptemplate variables to use. Moreyou can find out at$footer message The footer message as defined in the admin settings, also the HTML for the footer region. $header HTML for the header region. $logo The path to the logo image, as defined in theme configuration. Gaurav Khambhala <> Building a Drupal Theme
  15. 15. Create template files - page.tpl.php$primary links (array) An array containing the links as they have been defined in the phptemplate specific configuration block.$sidebar left The HTML for the left sidebar.$sidebar right The HTML for the right sidebar. Gaurav Khambhala <> Building a Drupal Theme
  16. 16. Create Theme files Download Advanced theme construction kit from x-6.0.tar.gz Untar the downloaded file.atck was developed in a production environment for purposes of quickly building css and xhtml valid Drupal themes from scratch without having to un-theme an existing Drupal theme to do it. So you have all the required files for building drupal theme. Copy all these files and make required changes to .info file. Now go to Administer-Site Building-Themes. Enable the example theme. Gaurav Khambhala <> Building a Drupal Theme