I'm trying to use a custom template file within my Features module to handle a Views exposed form, but have been unable to figure out how to do so. I've seen a couple of other questions on here which seem to be the very same class of problem, but who's solutions have not worked for me.

I have been successful in getting both my template file and a preprocess function to take control, but it appears that they completely disable View's own preprocess function, which is necessary for the form to be generated correctly.

Presently, I am creating a theme hook in my custom module:

function mymodule_theme($existing, $type, $theme, $path) {
  return array(
    'views_exposed_form__people__page' => array(
      'base_hook' => 'views_exposed_form', // BTW, am I using this thing right?
      'template' => 'views-exposed-form--people--page', // (hook--view--display)
      'render element' => 'form',

I understand that this means my preprocess function will now be called, and I use that to add my template file into the mix:

function mymodule_preprocess_views_exposed_form__people__page(&$vars) {
  $vars['theme_hook_suggestions'][] = 'views_exposed_form__people__page';

This works, but now it looks like View's default preprocessor template_preprocess_views_exposed_form(&$vars) in Views' theme.inc isn't firing, and that's bad because that function needs to run for this to work properly.

I'm also struggling to understand the rules behind what functions and templates get used when. The system doesn't seem overly complicated, I've just had to piece how it works together from disparate sources. I may be operating under one or more misconceptions here, so let me know if you want to probe what I think I'm talking about.

2 Answers 2


Views provides an even easier way to do this via its views_api() hook:

function YOURMODULE_views_api() {
  return array(
    'api' => 3, // most probably 3 by this point in time
    'template path' => drupal_get_path('module', 'YOURMODULE') . '/theme',

After a cache/theme registry clear, this will incorporate any Views templates found in the theme directory of your module (For further reading, multi-year discussion here.)


Rather than outright overriding the theme item implementation (via your hook_theme()), you could use hook_theme_registry_alter() to add your preprocessing function to the theme item.

  • I knew that was an option, but I'm not clear on what the difference really is, in this case. My admittedly simplistic view of the hook_theme() and hook_theme_registry_alter() is that they're both for manipulating the theme registry, and that difference is that the alter function let's you mess with stuff that's already there, whereas the theme function let's you merely add stuff.
    – SpryDaniel
    Jul 21, 2013 at 1:28

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.