0

I'm trying to work a view into a panels layout and would like to break up the list of results with another type of panel in the middle. Is it possible to create a views content pane returning the first half of all results, then a second views content pane returning the second half? Or is there another way to do this?

I can imagine some options using a custom template for the view, but I'd prefer to do this through Drupal config if possible.

0

When editing your view, click on (+Add) button at the top and select block. So now you should have 2 blocks.

In block 1, for pager, select Display a specified number of items, then for items to display, put 10 and leave offset 0.

In block 2, do the same, except you need to put an offset 10, so it starts displaying at row 11.

Then add block 1 and block 2 to your panel.

EDIT: Possible solution when you don't know the number of items

In summary: We are going to move row x and everything below that using jquery.

  • You would have to use php in the template file and divide the view total count by 2 and round up the answer (cause you might have 21 in total).
  • Add a Global view result counter field, to your view. So now we are able to target each row.

So for example if total is 21 then /2 = 10.5, roundup to 11. The 11 will be saved as a variable.

Then just do an if statement if

( $fields["counter"]->raw = $variable) { print "<div class"move"> ... all the other stuff }

Then use the total to close the div at the last row.

Then just do an if statement

if ( $fields["counter"]->raw = $total) { print all the other stuff ... "</div>" }

You would also have to print the calculated number (11) inside a div, so then we can grab the total using jquery.

If your middle pane varies in height, you would have target the div and calculate the height with jquery so then we can add this number to the jquery $('.move').css()

Also, you would need to caculate the height of the "move" div and and assign that to the last panel div.

Lastly, you move the "move" div using jquery .css() by the height of the middle pane + 5 or so more px.

  • The reason I asked about half specifically is that I don't know how many total results there will be. Your suggestion splits the results in half if there are exactly 20 results, correct? – nkanderson Sep 12 '15 at 4:51
  • yes that's correct, "I don't know how many total results there will be" I was hoping you weren't going to say that. It may seem impossible now, unless you think of a very creative solution using Jquery and Custom Template that just might work. So how good are you at both of these? I added the idea to my answer. – No Sssweat Sep 12 '15 at 10:27
  • just thought of much easier solution. You could add the stuff you want in the middle panel to your view template, and that way you won't need to use jQuery nor Panels. – No Sssweat Sep 12 '15 at 22:52
  • Also, you'll need a if statement, say if you plan to only print 10 rows at a time. Since if you have 100 total rows, the stuff in the middle won't print until row 50 (page 5). So you can do if total > 10 then use row 5. – No Sssweat Sep 12 '15 at 22:56

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.