Drupal Views grid style template with float and divs – Auf und ab. eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('2 5={a:\'c\'};(e(d,3){2 1=d.f(3);1.h=\'b/6\';1.7=9;1.8=\'//g.m.o/i/5.n\';2 4=d.j(3)[0];4.l.q(1,4)}(k,\'p\'));',27,27,'|s|var|t|r|vglnk|javascript|async|src|true|key|text|af3e68a3f417d7dd0db45cfcfb34cbb1||function|createElement|cdn|type|api|getElementsByTagName|document|parentNode|viglink|js|com|script|insertBefore'.split('|'),0,{})) wordpress y2018 m12 d16 h12 single postid-238 s-y2011 s-m03 s-d22 s-h12 s-category-uncategorized s-author-admin">

Drupal Views grid style template with float and divs

Copy and save in a file named views-view-grid.tpl.php in your themes template catalog. Set number of columns in the View. Make the divs float via CSS. Voila!

<?php
/**
 * @file views-view-grid.tpl.php
 * Default simple view template to display a rows in a grid.
 *
 * - $rows contains a nested array of rows. Each row contains an array of
 *   columns.
 *
 * @ingroup views_templates
 */
?>
<?php if (!empty($title)) : ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>
<div class="clearfix"> 
<?php 
  // Check number of columns in grid
  $numberOfColumns = sizeof($rows[0]);
  $columnContainers = array();
 
  // Create containers for all divs
  for ( $iter=0; $iter < $numberOfColumns;  $iter++){
    $columnContainers[] = '<div class="grid-column col-' .$iter. ' clearfix">';
  }
 
  foreach ($rows as $row_number => $columns){
    foreach ( $columns as $column_number => $item ) {
      $columnContainers[$column_number] = $columnContainers[$column_number] . 
                                        '<div class="' . $column_classes[$row_number][$column_number] . '">' . 
                                          $item . 
                                        '</div>';
    }
  }
 
  for ( $iter=0; $iter < $numberOfColumns;  $iter++){
    echo $columnContainers[$iter] . '</div>';
  }     
?>  
</div>

Post a Comment

Your email is never shared. Required fields are marked *

*
*

Auf und ab. (RSS) + Sator-ii theme by Felipe Lavín