Skip to main content
added 645 characters in body
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Sorry, I did not bother to make it pretty-print, but the source of the generated page has the div structure you asked for. The code is abstract and has dummy rows array, so you can test it by simply pasting it in an empty phpPHP file and trigger it outside Drupal. Anyway you should get the idea.

Update

You used the PHP code from view-view.tpl.php. This is a template file with a broader picture on a view's output structure. In this file you don't have any control over the traversal (the foreach loop). It just says print $rows and that's it, meaning "print out the loop, whatever it looks like." What you need is to specify how the loop is generated - that is: open your view, open the Theming information and pick one of the tpl in the Style group (where tpl's contain the word unformatted). There you'll be able to mess with the loop. Remove my code from the former file and move it to that file. Rescan templates.

Sorry, I did not bother to make it pretty-print, but the source of the generated page has the div structure you asked for. The code is abstract and has dummy rows array, so you can test it by simply pasting it in an empty php file and trigger it outside Drupal. Anyway you should get the idea.

Sorry, I did not bother to make it pretty-print, but the source of the generated page has the div structure you asked for. The code is abstract and has dummy rows array, so you can test it by simply pasting it in an empty PHP file and trigger it outside Drupal. Anyway you should get the idea.

Update

You used the PHP code from view-view.tpl.php. This is a template file with a broader picture on a view's output structure. In this file you don't have any control over the traversal (the foreach loop). It just says print $rows and that's it, meaning "print out the loop, whatever it looks like." What you need is to specify how the loop is generated - that is: open your view, open the Theming information and pick one of the tpl in the Style group (where tpl's contain the word unformatted). There you'll be able to mess with the loop. Remove my code from the former file and move it to that file. Rescan templates.

Source Link
no more drupal
  • 5.5k
  • 2
  • 44
  • 84

Sure thing criscom. Below is a very rudimentary piece of code.

<?php
  $rows = array(
    1 => "row1",
    2 => "row2",
    3 => "row3",
    4 => "row4",
    5 => "row5",
    6 => "row6",
    7 => "row7",
    8 => "row8",
    9 => "row9",
    10 => "row10",
  );
?>

<?php
  $currIx = 1; // This will be our incremental index variable. Let's make it 1-based to maintin consistency with your example.
  $currWrapperIx = 1; // Wrapper counter
  $wasOpen = FALSE; // This variable will be used later as a flag to watch for properly closing wrapper divs.
?>

<?php foreach ($rows as $id => $row): ?>
  <?php switch ($currIx){
    // List the row indices that are supposed to begin a new wrapper.
    case 1:
    case 4:
    case 9:
      if($wasOpen == TRUE){ // Close current wrapper div before opening a new one.
        print "</div>\n";
        $wasOpen = FALSE;
        $currWrapperIx ++; // Increment the index for next wrapper's class.
      }
      // Open a new wrapper div
      print "<div class=\"wrapper-{$currWrapperIx}\">\n";
      $wasOpen = TRUE;
      break;
      
    default:
      // For other row indices do nothing.
    }
  ?>
  
  <div><?php print $row; ?></div>
  
  <?php $currIx ++; ?>
<?php endforeach; ?>

<?php
    // Close the last wrapper.
    if($wasOpen == TRUE){
      print "</div>\n";
      $wasOpen = FALSE;
    }
?>

Sorry, I did not bother to make it pretty-print, but the source of the generated page has the div structure you asked for. The code is abstract and has dummy rows array, so you can test it by simply pasting it in an empty php file and trigger it outside Drupal. Anyway you should get the idea.