The Definitive Guide to Drupal 7

Do My Changes Belong in a Module?

With each new release of Drupal, the theme layer becomes more and more powerful. With the advent of Render API and the ability to use alter hooks in themes, Drupal 7 is packed with more power than ever. As powerful as Drupal themes can be, there are still many things that just do not belong in the theme layer. As you are plugging away coding your awesome Drupal theme, constantly ask yourself these questions:

  • Does what you are trying to accomplish require an SQL query? These should never be in a theme. Period.
  • Does your task seem particularly difficult to accomplish? Are you completely rebuilding data?
  • Are your changes really theme-specific? For example, if you are changing form labels and descriptions, should these be available if you were to disable your theme?

If the answer to any of these questions is yes, then your changes belong in a module.

You are reading content from two chapters on Theme Development from The Definitive Guide to Drupal 7, written by Jacine Luisi and published by Apress on July 19, 2011. All rights reserved.