tidystorm

random techno-gab

Drupal 7 Create a sub-theme based on Bartik

I have copied this great information from opensourcecms.pro

Assume you want to customize the default Bartik theme bundled with Drupal 7. Since you know it is a bad idea to alter the core files, you are going to create a new sub-theme based on Bartik and make your modifications there.
Step 1: Create a copy
First, copy the directory /themes/bartik
Step 2: Rename the directory
Paste the base theme directory into the directory /sites/all/themes and rename it as you see fit. For purposes of our example, we’ll call it newsub. In other words, you should now have a complete set of themes files located at /sites/all/themes/newsub
Step 3: Delete unwanted files
The sub-theme will inherit almost everything from the base theme. (The exceptions are the .info file and the site logo image file.) Given that inheritance is the norm, you should eliminate everything from the sub-theme that you don’t plan to change. In other words, if you don’t plan to modify a particular file, delete it from the sub-theme’s directory.
Most people will want to consider keeping one or more of the templates and the template.php file, but this depends on your plans. If you intend to customize any of the existing templates, or create template suggestions, keep the relevant templates. If you want to modify any of the themable functions or create new ones, you will need the template.php file.
Open up your newsub directory and delete everything you don’t need. No matter what you plan to do, you should keep the .info file — your sub-theme has to have a .info file — and keep the /css and /templates directory, though you can delete the contents if you don’t plan to modify them.
Step 4: Update the theme name throughout
Next, let’s update the theme name inside all the files we’ve kept. We need to change every occurrence of “bartik” to “newsub.” If you’ve got a code editor, you can run a find/replace to get this done, if not, you’ll need to crack open each file and do this.
Step 5: Create your stylesheet
Next, let’s create a new .css file. This is a requirement for a valid sub-theme; you need at least one stylesheet. Create an empty file, name it newsub.css and put it in the /css directory.
Step 6: Update .info
Make sure your .info is now called newsub.info. Next, open up the file and perform the following operations on the contents:
1. Make sure the name field has been updated to reflect the name of the sub-theme.
2. Update the description line as you see fit – this information will appear inside the Theme Manager as a description for the theme.
3. Delete the lines for package and version.
4. Add a new line: base theme = bartik
5. Declare our new stylesheet by adding this line: stylesheets[all][] = css/newsub.css
6. Delete all other stylesheet declarations.
7. Save the file.
Note that sub-themes do not inherit custom regions from the parent theme. Therefore if you want to use any custom regions in the base theme, you will need to re-specify them in the sub-theme’s .info file. In the example we’ve just worked through, we’ve simply copied the Bartik .info file, so we already have the entire list of custom regions in the newsub.info file.
That’s all there is to it! At this stage you have a new, fully functional theme. If all has gone according to plan, your NewSub theme can now been seen inside the Disabled Themes section of your site’s Theme Manager.
Additional Tips – Overriding Templates
• If you wish to modify any of the templates included in the Bartik base theme, simply copy them over to your directory /newsub/templates and make your changes
• If you want to override other core templates, copy the original template and place it in /newsub/templates
• If you want to add a template suggestion, place the base template in /newsub/templates and create your new suggestion in the same directory
Additional Tips – Overriding Styles
• If you want to override a specific style, simply place the selector in /css/newsub.css
• If you want to override an entire stylesheet from the base theme, place a file of the same name in the /newsub/css directory.
Additional Tips – Overriding functions
• If you want to override an existing function, copy it into /newsub/template.php and change the name to match your new sub-theme.
Where to go to Learn More
• Sub-theme strcture and inheritance, http://drupal.org/node/225125 (note this has yet to be updated for Drupal 7, but is valid)
• Structure of the .info file, http://drupal.org/node/171205
• Overriding themable output, http://drupal.org/node/341628 (note this has yet to be updated for Drupal 7, but is valid)
• Using Base Themes, http://drupal.org/node/980434