Theme preprocess for module's template variables using dynamic path I am doing templating for a module that adds a block in the module's folder so that the template can be there, and it may be overridden in the theme if desired. I want the module to support different "sources" (but only one will be active/used at a time), which may each have a separate template and variable preprocessing. I have hook_theme() working, and the template works. But the .vars.php file I have contains the preprocess function, and it doesn't get called.

Here is a basic example of what I have:

/MODULE.module

function MODULE_theme($existing, $type, $theme, $path) {
  $source = '';
  switch ($source) {
    case 'SRC_A':
      $path .= '/sources/SRC_A/theme';
    default:
      $source = 'default';
      $path .= '/theme';
  }

  return array(
    'MODULE_block' =&gt; array(
      'path' =&gt; $path,
      'variables' =&gt; array('data' =&gt; array(), 'source' =&gt; $source),
      'template' =&gt; 'MODULE-block',
    )
  );
}


/MODULE/sources/SRC_A/theme/MODULE-block.tpl.php

(contains template HTML with references to PHP variables)


/MODULE/sources/SRC_A/theme/MODULE-block.vars.php

/**
 * Implements template_preprocess_HOOK() for theme_MODULE_block().
 */
function template_preprocess_MODULE_block(&amp;$vars) {
  // Add variables before they get to the template file.
  $vars['some_key'] = 'some_value';
}


I originally was trying to modify the $template value in hook_theme() to MODULE-block--SRC-A, but I decided that didn't matter, and if only one template is active at once I should just call them all MODULE-block.tpl.php regardless of the source, since they are all in different folders.

The template works, and adding a template in my theme will correctly override it. But the .vars.php file with the preprocess function does not seem to do anything unless it is in my actual theme and is THEME_preprocess_MODULE_block instead.

I'm still pretty new to this, but I looked at a lot of pages online, and there aren't any similar examples in my code base that have a module-specific .vars.php file that is located in the module's folder rather than in the theme.

I do not know what I am doing wrong. Any ideas?
I figured it out. There was already a preprocess function with the name template_preprocess_MODULE_block in the module file. Declaring the same function a second time has no effect.