3

I have already 20+ view pages that use exposed filter for filtering out content. What i want is to place the filter in the sidebar and not in the top of the page (different region).

I can exposed the view filters as a block and this will work fine but i have over 20+ view pages and that mean 20+ new blocks, increasing the load for the not dev users.

The better approach will involved using a hook to check the views id and if the match (1-20+ ids i will have) then move the exposed filter to a different region.

Is this possible?

1 Answer 1

0

That's interesting, there may be a possibility...

This would work if you 1) have the View object, or 2) if you can figure out which view to load via the url path or something...

You would put this code in a preprocess function for your region, or perhaps a template although that wouldn't be recommended. However you insert it into your region, the following code will generate the exposed filter form markup:

$view = views_get_view('view_name');
$form_state = array(
            'view' => $view,
            'display' => $view->display_handler->display,
            'exposed_form_plugin' => $view->display_handler->get_plugin('exposed_form'),
            'method' => 'get',
            'rerender' => TRUE,
            'no_redirect' => TRUE,
            'always_process' => TRUE, // This is important for handle the form status.
          );
          $form = drupal_build_form('views_exposed_form', $form_state);

          $exposed_filter_markup = drupal_render($form);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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