0

In Drupal 7 I created a view with an exposed form in a block. The view has a "page" display.

Users can make their searches using the exposed form in the pages where I placed the block.

I would like to put the filter also in the results page, but it is placed always after the results, while I would like to have that between the page title and the results.

Example:

what happens

PAGE TITLE

VIEWS RESULTS

EXPOSED FORM

what I would like to do

PAGE TITLE

EXPOSED FORM

VIEWS RESULTS

Any idea? thank you in advance


As I write below, I found the solution:

I had to:

1) Create the view 2) Expose the form 3) Add a "Global PHP" in the view header with the following code:

$block = block_load('views', '-exp-myview-page');
$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
print $output;

Surely it can be done also using template instead of the php in the header.

migrated from stackoverflow.com Dec 16 '13 at 20:13

This question came from our site for professional and enthusiast programmers.

0

You can override View tpl file and do the arrangement as per requirement. Also check the setting for exposed for under view.

  • ok, this could be a general answer for views... :-) The problem is, how I have to do that? – lorenzo Dec 16 '13 at 6:50
  • override views-view.tpl.php for your view and change the placement of header-title as per requirement. Its not good idea to use php in textarea, kills performance. On other pages, you can handle by placing the exposed block in proper region. – Prashant Kanse Dec 21 '13 at 8:01
0

Prashant's answer won't work because you use an exposed block to filter results. The default views template for exposed filters is the same way as you want it, eg, Title -> filters -> results. The block submit button directs you to the page where the results are. Where, if I am correct, you have also put this block in.

The solution: You shouldn't expose the filters in a block, this way they will be shown on the search-page, and by default, are on top of the page and stay there, and results will be below them.

Or: put your exposed-block in a different region, or duplicate the view.

  • I need the block also in a different page, so I have to expose that. I can put the exposed block in a different region in the view page, but this is not what I'm looking for. Duplicate the view?? – lorenzo Dec 17 '13 at 6:40
0

I found the solution to my own question.

I had to: 1) Create the view 2) Expose the form 3) Add a "Global PHP" in the view header with the following code:

$block = block_load('views', '-exp-myview-page');
$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
print $output;

Surely it can be done also using template instead of the php in the header.

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.