Hi,

Having successfully learnt to theme views output, I turn my attention to input. How do you customize/theme an exposed filter? I have an exposed search: search terms filter, but the input box is too narrow for my liking. Is this a simple matter and, if so, how do I go about doing it?

Comments

merlinofchaos’s picture

Status: Active » Fixed

views-exposed-form--viewname--displayname.tpl.php should work. Look in the 'theme' directory in the views module for the original template. You can also form_alter the form (views-exposed-form) as well.

edmunsta’s picture

Status: Fixed » Postponed (maintainer needs more info)

Theoretically, if I copy the original template entirely into the new template, should it display just as before? I have created views-exposed-form--myviewnamehere--page.tpl.php, and copied exactly the content of views-exposed-form.tpl.php. But when I put the new file into my theme folder, though the view output appears correctly, all the exposed filters have disappeared. A var_dump on $widget and $id both return NULL.

merlinofchaos’s picture

Oh, you're probably being hit by a core bug. Youll need to upgrade to Drupal 6.x-dev (There's a patch mentioned in the help file on the theme: Information section too; you can try that patch though it's now two patches and probably getting a little difficult to apply).

domesticat’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Performing a mass closing of all issues over 180 days old. Please reopen if needed.

doublejosh’s picture

This is technically how to get to theming the exposed filter form block area, but doesn't help you with the action form itself since it's already been built :(

Makku01’s picture

excuse me but I have no idea how to name the template file for the block of a specific filter. the block ID is block-views-[VIEWNAME]-block_1. How do I have to name the tpl.php for the block? any advise is greatly appreciated! THX

doublejosh’s picture

Don't believe it's possible to have template for a specific filter item. Only the full block.
That file would be: views-exposed-form--MYVIEW--block-1.tpl.php

To mess with filters try a custom module. Here are two example of alterations I use. Hope that helps.

function MYMODULE_form_views_exposed_form_alter(&$form, &$form_state) {
  // EXAMPLE #1
  // Change Promoted to front page into a single checkbox.
  // (Requires that the filter namespace value is "featured").
  unset($form['featured']['#options'][0]); // Kill off the "No" option.
  $form['featured']['#multiple'] = true; // Make this into an on/off choice.
  if($form['#info']['filter-promote']['label']) {
    // Optionally, move the filter label into the "Yes" label.
    $form['featured']['#options'][1] = $form['#info']['filter-promote']['label'];
  }
  $form['#info']['filter-promote']['label'] = ''; // Kill off the master label used above.
  // EXAMPLE #2
  // Change a number filter into a drop down of values (to be used as a greater than within views).
  $f = 'number_field';
  if(array_key_exists($f,$form)) {    
    $form[$f]['#type'] = 'select';
    $form[$f]['#size'] = 1;
    $form[$f]['#options'] = array(1=>'Small', 50=>'Medium', 150=>'Large');
  }
}