Table of Contents

Preface_1

Chapter 1 : The Elements of a Drupal Theme_5

What is a Theme? 5

What is a Templating Engine? 6

The Range and Flexibility of Drupal Themes 7

What You See on the Screen 8

The Big Picture: How Drupal Displays a Page 10

The Importance of Themes in Drupal 12

Key Concepts 12

Build with Blocks 14

Intercept and Override 16

The Contents of the Drupal Distro 17

The Theme Files 21

The Files of a PHPTemplate Theme 22

The Files of a Pure PHP Theme 23

Summary 24

Chapter 2: Theme Set Up and Configuration_25

Finding Additional Themes 25

Installing an Additional Theme 28

Configuring a Theme 32

Theme-Specific Configuration Options 33

Global Configuration Settings 37

Managing Modules and Blocks 38

The Module Manager 38

The Blocks Manager 40

Adding PHP to Blocks 45

Theming in Action: Dressing Up Garland 47

Set the Color Scheme 48

Change Display Settings 49

Upload Logo 50

Global Configuration 50

Enable Modules 52

Manage Blocks 53

Add Some Dummy Content and Links 54

Set Access Levels 54

Create a Custom Block 55

Set Block Visibility 56

Uninstalling Themes 60

Summary 60

Chapter 3: Working with Theme Engines_61

What is PHPTemplate? 61

How does it Work? 62

Getting Started with PHPTemplate 65

A Look at the Theme Engine Files 66 A Look at the Key PHPTemplate File Contained in the Theme 71

Two Contrasting Examples 77

A Basic PHPTemplate Theme—Gagarin 78

A More Complex PHPTemplate Theme—Garland 78

Alternative Theme Engines 80

PHPTAL 80

Smarty 81

PHP XTemplate 81

Installing Additional Theme engines 82

Summary 82

Chapter 4: Style Sheets and Themeable Functions_83

A Guide to Drupal Style Sheets 83

Identifying Themeable Functions 86

A Guide to Themeable Functions 87

Aggregator Module Functions 87

Block Module Functions 88

Book Module Functions 88

Color Module Functions 88

Comment Module Functions 88

Drupal Module Functions 90

Filter Module Functions 90

Form Functions 90

Forum Module Functions 92

Locale Functions 92

Menu Functions 93

Node Module Functions 93

Pagination Functions 94

Poll Module Functions 94

Profile Module Functions 95

Search Module Functions 95

System Module Functions 96

Taxonomy Module Functions 96

Theme Functions 97

Upload Module Functions 99

User Module Functions 99

Watchdog Module Functions 100

Summary 100

Chapter 5: Intercepts and Overrides_101

Overriding the Default CSS 101

CSS Overrides in Action 103

Overriding Functions 105

Where to Place Overrides 106

How to Name Your Overrides 107

Overrides in Action: How Garland Works 108

Intercepting PHPTemplate Files 109

Overriding Themeable Functions in Garland 110

Various Approaches to Overrides 111

Intercepting and Substituting Files 111

Placing Overrides in the Theme's template.php File 112

Modifying the PHPTemplate Engine Files 113

Placing Overrides in Dedicated Files 113

Intercepting Template Files 116

Summary 117

Chapter 6: Modifying an Existing Theme_119

Setting Up the Workspace 119

Planning the Modifications 120

Cloning a Theme 122

First Look at Zen/Tao 123

CSS in Zen/Tao 123

Themeable Functions in Zen/Tao 126

Turning Zen into Tao 127

Configuring the Theme 127

Set Global and Theme Configuration Options 128

Enable Modules 128

Set User Access 129

Create Dummy Content 129

Set Up Menus 129

Add New Regions 131

Enable and Configure Blocks 133

Position Blocks 134

Adapting the CSS 135

Setting the Page Dimensions 136

Formatting the New Regions 136

Fonts and Colors 137

Formatting the Sidebars and Footer 140

Formatting the Menus 141

Formatting the Search Box 142

Formatting the Comments Form and Output 143

Adapting the Themeable Functions 144

Modifying template.php 144

Creating a New Template File 145

Before and After 147

Summary 148

Chapter 7: Building a New Theme_149

Planning the Build 149

Build a New PHPTemplate Theme 152

Building a page.tpl.php File 153

Insert DocType and Head 156

Insert Body Tags 157

Lay Out the Page Divisions 158

Place the Functional Elements 158

The Final page.tpl.php File 165

The style.css File 169

A Look at Our New Theme 178

Extending Your PHPTemplate Theme 179

Working with Template Variables 179

Variables Available in block.tpl.php 179

Variables Available in box.tpl.php 180

Variables Available in comment.tpl.php 181

Variables Available in node.tpl.php 181

Variables Available in page.tpl.php 182

Intercepting and Overriding Variables 184

Making New Variables Available 185

Dynamic Theming 185

Using Multiple Templates 186

Dynamically Theming Page Elements 189

Creating Dynamic CSS Styling 191

Build a New Pure PHP Theme 193

Required Elements 194

HTML Headers 196

Head of Document 196

Implementing the Features 196

Favicon 196

Logo 197

Site Name 197

Site Slogan 197

Primary and Secondary Links 198

Sidebars 198

Sidebar Left 198

Sidebar Right 199

Main Content Area 199

Title and Breadcrumb Trail 199

Tabs 199

Help 199

Messages 200

Content Region 200

Footer 200

Theme Closure 200

Overriding Functions 201

Summary 201

Chapter 8: Dealing with Forms_203

How Forms Work in Drupal 203

Modifying and Overriding Form Functions 206

Adding HTML via Function Attributes 207

Using form_alter() 207

Overriding Form Functions from template.php 209

Creating Custom Templates for Forms 211

Page Templates 211

Block Templates 212

Templates for Forms Output 213

Common Form Issues 214

Modifying Data Labels and Other Text 214

Using form_alter() 214

Override the Function 215

Create a New Template 215

Add a Node 215

Modifying the Styling of a Form 216

Using form_alter() 217

Override the Function 217

Create a New Template 217

Using Images for Buttons 217

The Default Forms 218

The User Forms 219

The Login Forms 219

The User Registration Form

220

The Request Password Form

221

The Edit User Info Form

222

The Default Contact Form

223

The Search Forms

224

The Theme Search Form

225

The Block Search Form

226

The Page Search Form

226

The Advanced Search Form

227

The Search Results Page

228

The Poll Module Forms

228

The Poll Block Form

229

The Poll Page Form

229

Summary

229

Appendix A

231

Index

239

0 0

Post a comment