官术网_书友最值得收藏!

Chapter 2. Beyond the Basics

We will be covering the following recipes in this chapter:

  • Understanding the anatomy of a theme
  • Creating a sub-theme based on a core theme
  • Overriding base theme elements in a sub-theme
  • Changing the screenshot image of a theme
  • Including a CSS file in a theme
  • Enabling CSS optimization
  • Creating the mysite module to hold our tweaks
  • Adding a CSS file from a module
  • Displaying a different theme for each day of the week
  • Creating a fresh look using the color module

Introduction

One of the more prevalent adages with respect to Drupal development and theming is:

Do not hack core!

Modules, themes, and other files which come with a stock Drupal installation should never be edited directly. In other words, we really should not need to modify anything outside the sites folder which is designed to contain all our changes and customizations. The reasoning behind this is that most, if not all, aspects of core are accessible and modifiable through a clean and non-invasive process using Drupal's APIs. Therefore, hacking core modules and themes to get things done is almost always unnecessary and ill-advised.

Another reason why directly editing core modules and themes, or for that matter, even contributed modules and themes, is that whenever an upgrade of Drupal or said modules and themes takes place, we will very likely be overwriting the changes we have made, or at the very least, make the upgrade a trying exercise.

With respect to themes, let us take the example of a core theme such as Garland. As previously mentioned, it is a poor practice to edit the theme directly. The Drupal way is to extend the existing core theme using a sub-theme which, by default, is more or less an identical copy. This sub-theme can then be extended further and customized by overriding elements of the base theme,such as its stylesheets, template files, template variables, and so on.

In this chapter, we will look at the building blocks of a basic theme and then familiarize ourselves with the concept of the sub-theme and the various techniques available to extend, override and modify it according to our requirements.

主站蜘蛛池模板: 顺义区| 长汀县| 句容市| 三门峡市| 老河口市| 包头市| 常熟市| 阿克陶县| 綦江县| 红原县| 山东| 安康市| 封丘县| 湟源县| 偃师市| 阿图什市| 宣威市| 长垣县| 盈江县| 定州市| 桃江县| 攀枝花市| 福州市| 正安县| 阳春市| 墨竹工卡县| 双辽市| 义马市| 焦作市| 庆安县| 乌海市| 洛浦县| 惠东县| 霍邱县| 富阳市| 翼城县| 东乡族自治县| 集安市| 涞水县| 城口县| 鞍山市|