title: Silverstripe Iterator check if row is full
body: <p>I'm looking for a efficient way to check if a row is full (a row has 12 columns) inside a loop. </p>
  
  <p>The case is as follows, i have a Page type that can hold multiple Video's. These video's can vary in column size. e.g the first video can be set to 12 columns, the second to 8, the following to 4, etc.</p>
  
  <p>The way i'm doing this now, that works, is:</p>
  
  <pre><code>&lt;div class="row"&gt;
      &lt;% loop $MediaTest %&gt;
          &lt;% if $Row %&gt;
              &lt;/div&gt;&lt;div class="row"&gt;
          &lt;% else %&gt;
              &lt;% include MediaBlock FixedRatio=true %&gt;
          &lt;% end_if %&gt;
      &lt;% end_loop %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This loops over data returned by the method</p>
  
  <pre><code>public function getMediaTest()
  {
      $out = new ArrayList();
      $cols = 0;
      foreach ($this-&gt;Media() as $mediaItem) {
          $cols += $mediaItem-&gt;Size;
          $out-&gt;push($mediaItem);
          if ($cols &gt;= 12) {
              $cols = 0;
              $row = new ViewableData();
              $row-&gt;Row = true;
              $out-&gt;push($row);
          }
      }
  
      return $out;
  }
  </code></pre>
  
  <p>But i'm questioning the efficiency of this solution, because of looping the data and altering before passing it to the next loop (in template).</p>
  
  <p>I was thinking about extending the class <code>SSViewer_BasicIteratorSupport</code> with a method <code>Row()</code> that i could call in the loop. But this class is not extendable. I've also tried subclassing the class and replacing it with the <code>Injector</code> configuration.</p>
  
  <p>I'm hoping to get your insights in this case, maybe the solution is efficient enough, but i'm always open to learn better more efficient solutions!</p>
  
  <p>Thanks</p>