6

I'm trying to display the same views exposed from block twice. Once in the left nav and once in content top. With multi block I can clone the block and I am able to display both. However, I would like the left nav form to have less exposed filters.

The problem is that in hook_form_alter() and hook_preprocess_views_exposed_from() there are no unique identifiers that I can check to alter the form. It runs through the hooks twice but I cannot seem to know if I am dealing with the left nav form or the content top form.

Does anyone have any insight into this?

I tried the code below which works for views 2 and was going to create my own block and render the form. But I cannot get the code to work for views 3.

$view = views_get_view('brands');
$view->set_display('page_2');
$view->init_handlers();

$form_state = array(
  'view' => $view,
  'display' => $view->display_handler->display,
  'method' => 'get',
  'rerender' => TRUE,
  'no_redirect' => TRUE,
);

$output = drupal_build_form('views_exposed_form', $form_state);
$blocks['content'] = $output;

Am I looking in the wrong direction?

3

This code worked for me. I'm using Views 6 Alpha 4.

$view = views_get_view('your_view');
$view->set_display('the_display_you_want_that_have_a_exposed_block');
$view->init_handlers();
$exposed_form = $view->display_handler->get_plugin('exposed_form');
print $exposed_form->render_exposed_form(true);
  • This works for D7 V3 as well – acouch Nov 16 '12 at 21:36
2

1> Can't you add one more display of the same view and override filters for that display? If I get your question correctly then that should do it, you want 2 diff versions of exposed filters in block from a view.

Suggestion for multi block problem:

2> I would rather use context module - http://drupal.org/project/context to deal with multiple same blocks on the same page and other block visibility issues. This prolly won't solve the current problem at hand but is a better practice going fwd compared to multi block and block clone strategies.

  • That is definitely plan b. What I'm trying to avoid is having 2 views that do the exact same query. I would prefer for potential future growth to have only one point of management. However, having a different display in the same view isn't that bad. I wanted to see if anyone has discovered a clever way to accomplish this. I also prefer context. It's the most highly used module in our office. The context add assets module birth place was in our office. – Jepedo Mar 19 '11 at 12:36
0

I use some different code to create a block with a views form in (for a different reason, to display the form as a page callback, but it should still work).

 $module = 'views';
 $delta = '-exp-my_block_id';
 $block = (object) module_invoke($module, 'block', 'view', $delta);
 $block->module = $module;
 $block->delta = $delta;
 return theme('block', $block); 

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.