Hi,

I have a suggestion for views integration: On the "row plugin", there are already options for specifying alternating view modes for different elements in the result list. (For up to 20 items). Could that option be extended for a more general "even" and "odd" row option?

Let me describe what I'm trying to do:

I have a list of nodes which contain some text and an image. I have created two view modes which use a 2 column layout to put the text and image next to each other into separate columns. One view mode has the image in the left column, the other one in the right column.

Now I would like to create a view which renderes any number of those nodes on one page, rendering the image on the left for all nodes in even rows, and image on the right for all odd rows.

Sorry if this is already possible somehow...

Comments

dooug’s picture

Component: Code » Miscellaneous

I think this could be accomplished by using views blocks and the hook_views_pre_render. Another solution might be views_php module, but it is very buggy in D7.

Maybe some odd/even views filter could be rolled into a views plugin? Although the code below probably wouldn't be the best way to accomplish it.

I just had two similar displays and removed odd/even results from each. This is my example from my template.php (change the ALLCAPS to fit your theme name & views display names)

<?php
/**
 * Implements hook_views_pre_render().
 */
function THEMENAME_views_pre_render(&$view) {
  switch ($view->current_display) {
    case 'DISPLAY1':
      foreach ($view->result as $i => $val) {
        if ($i % 2) 
          unset($view->result[$i]);
      }
      break;
    case 'DISPLAY2':
      foreach ($view->result as $i => $val) {
        if (!($i % 2)) 
          unset($view->result[$i]);
      }
      break;
  }
}
   
?>

@bforchhammer,
Does that solve your request?

bforchhammer’s picture

Thank you, I haven't tried it but it looks like that might work...

At the moment I'm fine with up to 20 items; just thought it would be nice to have. And isn't the alternating view modes an addition by display suite? If yes it probably shouldn't be too hard to add 'even' and 'odd' classes as well, no?

swentel’s picture

Status: Active » Fixed

I'm going to mark this fixed for now. There's an alter possibility now (hook_ds_views_view_mode_alter). While the use case is interesting, I'm going to try and jam in any use case that exists. However, in case suddenly 20 people are interested in this, I'll consider it - even more when a patch would be posted :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

polishyourimage’s picture

I'm also very interested in this feature.

jawi’s picture

interested!

bettibio’s picture

I'm very interested in this feature.

ja_ca’s picture

Issue summary: View changes

I'd be interested too.

ipwa’s picture