Saturday, December 13, 2008

Book Review: Ric Shreves's "Drupal 6 Themes"

Review of Shreves's Drupal 6 Themes

If you are familiar with Packt titles then the layout, style and presentation of this one will come as no surprise. The book begins with an outline of what is to follow, the conventions used to print code, what is needed to follow the book (Drupal 6!), an invite to provide feedback, errata reports, download code examples piracy concerns and questions.

I am reviewing this as a slow learning learner of Drupal. Still a 'Drupal site virgin' (let's be clear about that) I attend the NW England Drupal group in Manchester and greatly enjoyed Drupalcon 2008 in Szeged, Hungary. Like my previous review of Mercer's Drupal 6 book in April this is a (laborious) chapter by chapter review, but hopefully helpful for all that (maybe I can get a job as a proof reader?).

So my upfront conclusion is that this is a good buy. It's not a very technical book, but it is definitely heading in that direction with the content of one or two chapters reminding me of the Pro Drupal volume. This no doubt reflects Shreves’ title with the book being well focused as you would expect.

Chapter 1 introduces the elements of a Drupal theme, with much needed instant foot and hand-holds by listing three key concepts (ways to theme) employed through the book:

  1. Theming in whole or part
  2. Building with blocks
  3. Intercept and overrides

These are covered in turn additionally pointing out aspects of Drupal that can confuse beginners, the admin theme and this being the same as the default theme. There's help with explanations of blocks, regions and how these relate to modules.

There's some text on page 11: it does hit the mark, but I think it might be improved with some illustration. That said, buyers of this book are likely to make ready sense of - "The recognized best practice approach to customising themes emphasizes making changes at higher levels, primarily to the theme files themselves." I raise this point as Ric draws attention to (what I understand is) a critical development approach within Drupal that something here deserves promotion as one of book’s 'important notes'. A figure of what constitutes Drupal's highest processes and what needs to be left in its original state might make the text clearer. This is difficult for authors, because if readers don't know this then perhaps they need to grasp some fundamentals first? As to which Ric Shreves explains what a theme is; a theme engine; and how all this makes Drupal flexible - with regions being placeholders.

Contrary to the point above overall the book is well illustrated. The way Drupal displays a page is illustrated in five steps. The default themes are listed and shown as screen dumps as with the themes config pages. This for me is not a waste of page real estate. With intercept and overrides briefly mentioned chapter 1 closes by introducing the main theme file types, the notion of sub-themes, PHPTemplate Themes and Pure PHP Themes are also differentiated.

Chapter 2 furthers the push up the learning curve, by reviewing 1.) how to install and configure pre-existing themes; 2.) convert designs and 3.) build a theme from scratch. All are discussed by Ric in this book. Beginning with a default theme, this is customized as far as the basic configuration allows. As a longer-term Drupal learner the pace of change in Drupal means that some themes and modules have to catch up with the latest releases (my student career started with version 4.7). Shreves highlights this point, before seeking other compatible themes he runs through status reports and backup should a theme cause problems. Some of the mundane, but essential considerations of themes are discussed here 'terms of use', plus headache saving tips on the use of folders. Theme specific configuration options are differentiated from global configuration settings that primarily involve modules, blocks and visibility. This helped further my understanding, and reveals Drupal's flexibility applying to users, roles, page specific settings and the use of PHP applied to blocks p.54 with four code examples. The Drupal community - a great resource - is also raised. Chapter 2 closes by dressing up a default theme (Garland) to meet a client's requirements. Before and after screen images and instruction on how to uninstall a theme leads to chapter 3.

The main theme engines are covered in chapter 3. If you are going to roll your own it is essential you understand the main files, the code and format and how they interact - that is - how they relate to the administration functions. This is detailed, but very accessible contrasting a simple (basic) PHPTemplate theme with a more complex example. A crucial kernel of knowledge for the Drupal themer is the naming conventions used in Drupal. That is, how files names affect the precedence as Drupal searches for the elements that make up a page - the content and styling. Other theme engines are also discussed with links - as per other Packt titles - to additional resources.

Chapter 4 brings us to templates, stylesheets and themable functions and shows how they interoperate. Discussion of the default templates, variables and stylesheets includes advice on disabling CSS compression. There then follows a meaty treatment – a guide no less – of theming elements, such as, theme_box and theme_breadcrumbs p.90. I wish I had come across “Theming the Book Functionality” pp. 95-97 a while back, better late then never. Part of my problem is settling on the content I need for my site. The default book content type is useful. The guide here is very comprehensive running over pp. 90-126.

Chapter 5 tackles intercepts and overrides and begins with overriding the default CSS in the Garland theme, moving swiftly to overriding templates and the themeable functions covered previously. Page 132 has an important note on theme registry and the difference between substituting template and overriding templates p.133. One aspects of many Drupal books is that they can appear repetitious, but for me this actually helps as in Drupal it seems there is frequently more than one way to skin the proverbial cat. An illustration of file naming conventions and precedence helps reinforce previous chapters and the reader’s grasp of Drupal. Chapter 5 ends with more on placing function overrides in the template.php file, the use of dedicated template files (with a step by step example); where to place themable functions overrides; how to name them and Overrides in Action. The code examples reveal the difference between default template-block.tpl.php and Garlands equivalent p.140.

Chapter 6 sets out to create a theme by modifying an existing one. As I've been finding, this isn't just a case of your knowledge of Drupal but also having a work environment that suits you. I've an old copy of Dreamweaver (from Studio MX days) and have been looking at Eclipse, PSPad, NetBeans, TextMate, Komodo Edit and other editors and tools. Ric describes Dreamweaver here, so that it can handle theme files, using a server and the use of the popular (Drupal) Devel module. (In true newbie Drupaller style I've tended to install and enable quite a few modules, which can create complexities of their own. Enable them when you need them.)

The Zen theme is then used to create a new sub-theme. The non-trivial matter of planning is stressed. Theme creation by modification is then considered step-by-step: from copying the necessary folder, renaming files, configuring the new theme, to enabling default modules that may be needed to meet a client's brief. Menus leads to links and paths a great source of confusion to new Drupal initiates. Menus need a home so blocks are further discussed with reference to CSS. A very informative twelve pages. A themeable function is overridden, a technical sounding task, but easy to follow in the form of a breadcrumb trail. The final pages of chapter 6 address formatting the blog node. A list of variables is provided comprising 18 items from $context - $zebra and de-mystifies a great deal. Another before and after screen shot completes a really useful chapter.

Chapter 7 explains building a new theme. This is an equally systematic account with illustrations, code and treatment of the essential .info, tpl.php files. There is a top-down perspective too, with page structure explained through page divisions, the placement of links, and key page elements. A final three page code listing and a eight page CSS listing is a pause for breathe. Thischapter ends with a brief review of creating a pure php theme.

I've started to create a couple of themes in Drupal, but chapter 8 is rather advanced for me - I can't (yet) claim to be a Dynamic Themer. If you are intent on fully leveraging the power of Drupal this chapter is essential reading for you. Here Ric shows how to create a unique homepage template, a different template for a group of pages, assign a specific template to a specific page, and designate a specific template for a specific user (power indeed). It's clear how the earlier chapters come in here when dynamically styling blocks. Ric highlights the utility of the Theme Developer feature of the Devel module. I've used this feature, but have yet to question the provenance of a block or other page element. I can see how helpful it will be. Other site components are dynamically styled - comment module, forum, poll and nodes. Throughout the book Shreves acknowledges the '6' in the title: dynamic styling is covered with two pages on $body_classes and a two page listing of the conditions that can be applied, for example; no sidebars. This neatly introduces collapsible sidebars (columns). Template variables crop up again, which may be a bit technical for some beginners but then beginners have to learn...

On page 225 there's another mention of the (theme) registry. There's a crucial tip on clearing the registry. p.234. I'm surprised ‘registry’ and the modules mentioned in the book don't deserve an entry in the index. Unless I missed it Jquery also is not listed, which I suppose is excusable. In theming I would have thought that awareness of the potential of Javascript and javascript libraries in particular would be useful knowledge up front. Especially so with jQuery being a part of Drupal.

I have experimented with forms and CCK in Drupal and this is fun because very quickly you appear 'productive'. Chapter 9 explains forms, how they work and the existence of the form API and reference sources. Forms are a more accessible aspect of Drupal to appreciate as you can 'see' the form in the PHP code. As there’s no such thing as a free lunch, Ric then reveals five ways to modify Drupal forms. This is done by breaking down the complexity and explaining the dependencies.

Appendix A (described at one point as a chapter) is an informative guide to Drupal stylesheets, in addition to listing the css files, the stylesheets for the default themes are also provided.

Appendix B runs through the desirable contents of a themers’ toolkit.

CONCLUSION

Shreves is aiming for a specific audience with this book - a great help for any publisher. The book may not have much to offer the Pro Drupal expert, but for beginners in theming and intermediate Druapallers there is loads of goodness here. There's also an indication of what's to follow as readers ascend the stairway to Drupal heaven, which is a tantalizing prospect.

My thanks to the team at Packt Publishing for the review copy.

I'll be reviewing Bill Fitzgerald's "Drupal for Education and E-Learning"
in due course (once the review of Hall's "Digitize this Book" is complete)
so please stay tuned!

If the NW of England is within your reach and you are in the market for
Drupal 6 training in 2009 try menu&blocks.