Views group different number of divs of a view by wrapping them I have a views block that is displayed in the content section of a node. What I need is wrapping the rows of the views block by divs. I have a list of 10 divs like so:

&lt;div class="row-1"&gt;Some Text here&lt;/div&gt;
&lt;div class="row-2"&gt;Some Text here&lt;/div&gt;
&lt;div class="row-3"&gt;Some Text here&lt;/div&gt;
&lt;div class="row-4"&gt;Some Text here&lt;/div&gt;
&lt;div class="row-5"&gt;Some Text here&lt;/div&gt;
&lt;div class="row-6"&gt;Some Text here&lt;/div&gt;
&lt;div class="row-7"&gt;Some Text here&lt;/div&gt;
&lt;div class="row-8"&gt;Some Text here&lt;/div&gt;
&lt;div class="row-9"&gt;Some Text here&lt;/div&gt;
&lt;div class="row-10"&gt;Some Text here&lt;/div&gt;


Now I want to wrap the first 3 divs, div 4 to 8 and div 9 and 10 in a separate wrapper div like so.

&lt;div class="wrapper-1"&gt;
&lt;div class="row-1"&gt;Some Text here&lt;/div&gt;
&lt;div class="row-2"&gt;Some Text here&lt;/div&gt;
&lt;div class="row-3"&gt;Some Text here&lt;/div&gt;
&lt;/div&gt;
&lt;div class="wrapper-2"&gt;
&lt;div class="row-4"&gt;Some Text here&lt;/div&gt;
&lt;div class="row-5"&gt;Some Text here&lt;/div&gt;
&lt;div class="row-6"&gt;Some Text here&lt;/div&gt;
&lt;div class="row-7"&gt;Some Text here&lt;/div&gt;
&lt;div class="row-8"&gt;Some Text here&lt;/div&gt;
&lt;/div&gt;
&lt;div class="wrapper-3"&gt;
&lt;div class="row-9"&gt;Some Text here&lt;/div&gt;
&lt;div class="row-10"&gt;Some Text here&lt;/div&gt;
&lt;/div&gt;


How would I edit my views.tpl.php? Thanks!
Here is what worked for me. Mind that I only got it to work in an unformatted list format in views.

&lt;?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.
?&gt;

&lt;?php if (!empty($title)): ?&gt;
  &lt;p class="&lt;?php print $title ?&gt;"&gt;&lt;?php print $title; ?&gt;&lt;/p&gt;
&lt;?php endif; ?&gt;
&lt;?php foreach ($rows as $id =&gt; $row): ?&gt;
  &lt;?php switch ($currIx){
    // List the row indices that are supposed to begin a new wrapper.
    case 1:
    case 27:
      if($wasOpen == TRUE){ // Close current wrapper div before opening a new one.
        print "&lt;/div&gt;\n";
        $wasOpen = FALSE;
        $currWrapperIx ++; // Increment the index for next wrapper's class.
      }
      // Open a new wrapper div
      print "&lt;div class=\"wrapper-{$currWrapperIx}\"&gt;\n";
      $wasOpen = TRUE;
      break;

    default:
      // For other row indices do nothing.
    }
  ?&gt;
&lt;!--&lt;div &lt;?php if ($classes_array[$id]) { print 'class="' . $classes_array[$id] .'"';  } ?&gt;&gt;--&gt;
  &lt;div class="&lt;?php print $id ?&gt;"&gt;&lt;?php print $row; ?&gt;&lt;/div&gt;
&lt;!-- &lt;/div&gt;--&gt;

  &lt;?php $currIx ++; ?&gt;
&lt;?php endforeach; ?&gt;

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


Kudos go out to @Artur. Great support. Many thanks.