Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I made a View, and I exposed the filters in a block; then, in the block's administrative screen, I set this block not to appear in the view that belong. In the actual view I don't want to show this block. Instead, I want the filters to appear in the content as they normally would if I didn't expose them in a block.

If that makes any difference, I am using Drupal 7.

share|improve this question
up vote 4 down vote accepted

My understanding is that your view has exposed filters and that Exposed form in block is set to Yes.

To put the exposed form where it would appear if it weren't in block, you should be able to place the exposed form block into your Content region, above the view itself.

To have the exposed form displayed in both the view and a separate block, leave the form in the view and create a PHP block with the following body:

<?php
  if ($block = module_invoke('views', 'block', 'view', '-exp-YOUR_VIEW-YOUR_DISPLAY') ) {
    print $block['content'] ;
  }
?>
share|improve this answer

The accepted answer did not work with Drupal 7 for me. I followed http://www.drup-all.com/blog/exposed-filters-form-your-custom-block-drupal-7 with success. Code below:

/** implements hook_block_info() **/
function test_block_info(){
  $blocks = array();
  $blocks['custom_exposed_filter_form'] = array(
    'info' => t('Exposed filter form'),
    'cache' => DRUPAL_NO_CACHE,
  );
  return $blocks;
}

/** implements hook_block_view() **/
function test_block_view($delta = ''){
  $block = array();
  switch($delta){
    case 'custom_exposed_filter_form':
      $block['subject'] = t('Exposed filter form');
      $block['content'] = _test_get_exposed_filter_form();   
    break;
  }
  return $block;
}

/** Function to get the Exposed filter form **/
function _test_get_exposed_filter_form(){
  // Get a view from the database or from default views . "test" is the view name.
  $view = views_get_view('test');
  // Set the display as current.
  $view->set_display('page');
  // Acquire and attach all of the handlers to the view.
  $view->init_handlers();
  $exposed_form = $view->display_handler->get_plugin('exposed_form');
  return $exposed_form->render_exposed_form();
}
share|improve this answer
    
Though a great solution, be aware of issues when loading a block like this on a Panelized page. See drupal.org/node/26365523. – lmeurs Dec 16 '15 at 20:53
$block = block_load('views', '-exp-VIEW_NAME-VIEW_DISPLAY');
$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block)))); 
echo($output);
share|improve this answer
    
Can you provide a little summary of why/how this is different that the accepted answer? – MPD Feb 13 '13 at 23:30
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. – niksmac Feb 14 '13 at 3:42

There is a Views UI alternative to the accepted answer, at least with Views 3 / D7:

  • configure your view with the view exposed form you'd like to see on the view page
  • Clone that view and for sake of future remembering, call it search block
  • In the search block view, in advanced setup, set Show the exposed form in a block : Yes
  • It 's important that both views have the same path
  • Display the block where ever you'd like to

It's worth saying that with this method you can now edit the search block and remove some filters, add markup... (but no filters that would not be in the mother view I believe).

You can even reproduce steps and have different custom blocks pointing to the same view.

I've done that recently and found it very useful

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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