Preprocess function per content type I have a couple of content types which I need to preprocess in different ways. So template.php in my theme foo currently looks like:

function foo_preprocess_node(&amp;$variables) {
    if ('news' ==$variables['type']) _preprocess_news($variables);
    if ('event'==$variables['type']) _preprocess_event($variables);
    if ('alert'==$variables['type']) _preprocess_alert($variables);
    ...
}

function _preprocess_news(&amp;$variables) {
    ...
}

function _preprocess_event(&amp;$variables) {
    ...
}

function _preprocess_alert(&amp;$variables) {
    ...
}


I'd like to be able to specify a Drupal specific preprocess function which would hook on the content type's machine name. I tried using foo_preprocess_news but it is never called.

Is there a better way?
The zen subtheme accomplishes this by adding this to its theme_preprocess_node function:

function foo_preprocess_node(&amp;$variables, $hook) {
  ...
    // Optionally, run node-type-specific preprocess functions, like
  // foo_preprocess_node_page() or foo_preprocess_node_story().
  $function = __FUNCTION__ . '_' . $variables['node']-&gt;type;
  if (function_exists($function)) {
    $function($variables, $hook);
  } 
  ...
}


If you have a content type called 'news', then you would be able to create a function called foo_preprocess_node_news in your template.php file.