`
haohappy2
  • 浏览: 326253 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

How to create a subtheme in Drupal 6

阅读更多

Creating a subtheme is a powerful and flexible way of theming in Drupal. Drupal 6 made implementing subthemes relatively easy to do. There are a few basic concepts to understand before starting, but once underway, creating a subtheme is a simple straightforward process. In this post, I'll outline the process for creating a subtheme. This is meant to be a quick primer, not an exhaustive tutorial on the elements and features of subthemes.

Before going further, I must acknowledge that this post borrows heavily from two posts currently available on Drupal.org. For further information, you can refer to:

Subtheme Concept

A subtheme is a child theme that borrows certain attributes from a parent theme. This allows you to use an established theme and a derivative of that theme both on the same site without needing to alter or duplicate the original theme.

When set up correctly, a subtheme inherits the following attributes from its parent theme:

  • All style sheets
  • All template files
  • All functions and overrides defined in the parent theme's template.php file (if it has one)

However, there are other key attributes that the subtheme does not inherit, including:

  • the parent theme's logo (logo.png)
  • regions (if the parent theme has custom regions)

Creating a subtheme

For the purposes of this post, we'll use an example of setting up a subtheme called "mysubtheme" that will be using an installed version of the contributed "framework" Drupal theme as its parent.

  1. Create a folder in your custom "themes" folder and name it the with the name you have chosen for your subtheme. Ex: mysubtheme
  2. Add a .info file to your subtheme folder. To define this as a subtheme, your subtheme folder needs text document named (using our example): mysubtheme.info
  3. Add the following elements to your .info file:
    name = mysubtheme
    description = any descriptive text you wish
    core = 6.x
    base theme = <(folder)name of any core or contributed theme or subtheme, e.g. framework>
    stylesheets[all][] = mysubtheme.css
    

    This defines the name of your subtheme, any description you want (shows up on the themes admin page), the reference to the base theme from which you want to inherit, and a stylesheet for defining the styles from the parent theme and other CSS that the subtheme will be overriding.
  4. Set up your regions. If the parent theme has established a set of custom regions in its .info file (many do), you will need to copy the region settings from the parent's .info file and add them to your subtheme's .info file. Otherwise, you will not be able to use these regions in your subtheme. For the contributed "framework" theme in our example, this would look like:
    regions[left] = Left sidebar
    regions[right] = Right sidebar
    regions[content] = Content
    regions[header] = Header
    regions[nav] = Navigation
    regions[footer] = Footer
    
    This is a feature, not a bug. It allows you to have a totally different set of regions for your subtheme if you have the need for this. If you do, just define the regions you wish to have using the "regions [regionname] = RegionLabel" syntax. If you define new regions for you subtheme, you will also need to create a new page.tpl.php file which prints these regions and place this in your subtheme folder.
  5. Add any necessary template files. As mentioned above, your subtheme will inherit the parent theme's tpl.php template files. If you wish to override a specific template file -- as in the regions example in 4 above -- add the specific tpl.php file to your subtheme folder. Alter this file as you wish. It will override the corresponding template file of the same name in the parent theme.
  6. Add your subtheme's overriding CSS file (ex. mysubtheme.css) to the subtheme folder. Use this file for all your subtheme's style overrides. You can, of course, define and add additional CSS files for your subtheme. If you wish to have multiple custom stylesheets, be sure to add reference to them in your .info file.

Having completed these steps, your subtheme should be up and ready for use. Visit your themes admin page to enable the theme.

Happy theming!

分享到:
评论

相关推荐

    Drupal 6 Themes: Create new themes for your Drupal 6 site with clean layout and powerful CSS styling

    If you want to create a striking new look for your Drupal 6 website, this book is for you. This book is a revised, updated and expanded edition of Drupal 5 Themes, written specifically for Drupal 6. ...

    Drupal.8.for.Absolute.Beginners.1430264667

    You will first learn how to set up and customize a basic blog using Drupal, one of the most powerful and popular content management systems available today. From there you will learn the basics of ...

    Decoupled Drupal in Practice

    You will learn how to architect and implement decoupled Drupal architectures across the stack―from building the back end and designing APIs to integrating with front-end technologies. You’ll also ...

    Drupal 8 Explained: Your Step-by-Step Guide to Drupal 8

    Drupal 8 Explained is for people who want a fun and clear introduction to Drupal and requires absolutely no experience with Drupal, content management, site construction, programming, scripting, or ...

    Drupal.8.Development.Beginners.Guide.2nd.Edition.epub

    If you are a developer who wants to use Drupal to enhance your website project and web application to manage content, this book is for you. Whether you are new to Drupal or an experienced web ...

    Learning Drupal 6 Module Development

    Are you a Drupal developer looking to update to version 6? This book covers the new and updated APIs to guide your transition to Drupal 6. The new menu system, the Forms and Schema APIs, and many core...

    drupal6版本(这是drupal6)

    Drupal 6 是一个开源的内容管理系统(CMS),发布于2008年,是Drupal历史上的一个重要版本。这个版本引入了许多新功能和改进,为网站开发者提供了更强大的工具和更大的灵活性。在本文中,我们将深入探讨Drupal 6的...

    Drupal.8.Configuration.Management.1783985208

    Additionally, you will learn how to migrate configuration from Drupal 6 and 7 to Drupal 8 and how to manage configuration for multilingual websites. Table of Contents Chapter 1. Understanding ...

    drupal 6.12

    Drupal requires access to a database in order to be installed. Your database user will need sufficient privileges to run Drupal. Additional information about privileges, and instructions to create ...

    Drupal 6 Site Builder Solutions, Build powerful web site features for your business and connect to your customers through blogs, product catalogs, newsletters, and maps

    Drupal is a powerful, free system that anyone can use in order to create their own website. With such a powerful tool at your fingertips there is no longer any need to pay professionals to design a ...

    Drupal 8 Module Development 2nd Edition

    In his spare time, he runs webomelette, a Drupal website where he writes technical articles, tips, and techniques related to Drupal development. Table of Contents Developing for Drupal 8 Creating ...

    drupal6 mime 6.0

    Drupal 6 是一个开源的内容管理系统(CMS),广泛用于构建网站和Web应用程序。Mime模块是Drupal 6的一个关键组件,特别设计用于处理和发送HTML格式的电子邮件。在 Drupal 中,MimeMail 模块提供了丰富的功能,使得...

    Drupal 6 Panels Cookbook

    ### Drupal 6 Panels Cookbook #### 知识点详解 **一、Drupal 6 简介** Drupal 是一款开源的内容管理系统(CMS),以其强大的功能、灵活性以及社区支持而闻名。Drupal 6 是 Drupal 发展历史上的一个重要版本,在...

Global site tag (gtag.js) - Google Analytics