I got into a discussion with co-workers today after reviewing some code on a Drupal 6 project.

When creating a module, I tend to define all template preprocessor functions by including the module name

function mymodulename_preprocess_news_item(&$vars){ ... }

If another module/theme needs to override/expand this, I add the function definition with the new module/theme name. This is how I've come to understand the theme layer to work.

My co-worker's mentioned that I should be using the following instead for custom preprocessor definitions:

function template_preprocess_news_item(&$vars){ ... }

According to the documentation on theme(), template_preprocess gets executed before anything else so I'm leaning towards agreeing with my co-workers since these are custom theme elements and the originating module should process the initial content.

I am curious if there are any best practices/opinions out there on this matter.


2 Answers 2


Why not look at drupal core for best practice which favors template_process_X.

Also for some processors both template_preprocess and module_preprocess hooks can get called, see template_preprocess_block and system_preprocess_block as an example.

  • Part of the confusion is that nearly every example or tutorial is written for someone who wants to override a theme function from core. Even module examples seem to follow this "mymodule_preprocess.." format. What I take away from the core and from the description of theme() is that the initial definition of a preprocessor SHOULD be named with template instead of the module/theme name to ensure that it is setup properly. Would you agree with this? Feb 1, 2012 at 20:09
  • 1
    @PrairieHippo Both will work, the most "correct" way would be to use template_ for your own theme preprocess hooks. Views also uses this setup.
    – googletorp
    Feb 1, 2012 at 20:18

Whether or not it's best practice, I've always made sure that a module's code only includes functions that begin with the module name or underscorename. With that in mind when preprocess()ing, I've put the template_ ones in my theme's template.php file. That way, I know where everything is. Also, this keeps things "in order" with respect to drupal's theme hierarchy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.