Modifying Bonus Grid View to call a custom template file

viz8 - November 27, 2008 - 10:20

Hi. I'm trying to modify the code on the Bonus Grid View so that it calls a particular template file (instead of creating the html itself), but i'm having no luck. I'm a bit new to drupal and php, so please bear with me. Below are the before-and-after pieces of code (the before part is straight from the Bonus Grid View). I'm guessing the problem is because i'm missing the return theme('item_list', $items); bit that's common to all list views, or some type of theme for the array, but i'm not sure. Either way, I don't know where i would insert the theming function. Any hint in the right direction is greatly appreciated. Thanks in advance!

BEFORE:

function foliage_views_bonus_view_grid_newGridView($view, $nodes, $type) {
  drupal_add_css(drupal_get_path('theme', 'foliage') .'/views-list-newGridView.css');
  $fields = _views_get_fields();
  $content = '<table class="view-grid view-grid-' . $view->name . '">';
 
  // set default count.
  $cols = $view->gridcount ? $view->gridcount : 4;

  $count = 0;
  $total = count($nodes);
  foreach ($nodes as $node) {
    $item = '';
    if ($count % $cols == 0) {
      $content .= '<tr>';
    }

    foreach ($view->field as $field) {
      if ($fields[$field['id']]['visible'] !== FALSE) {
        if ($field['label']) {
          $item .= "<div class='view-label view-label-$field[queryname]'>" . $field['label'] . "</div>";
        }
        $item .= "<div class='view-field view-data-$field[queryname]'>" . views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view) . "</div>";
      }
    }
    $content .= "<td class='view-grid-item'><div class='view-item view-item-$view->name'>$item</div></td>\n";

    $count++;
    if ($count % $cols == 0 || $count == $total) {
      $content .= '</tr>';
    }
  }
  $content .= '</table>';
 
  if ($content) {
    return $content;
  }
}

and AFTER:

function foliage_views_bonus_view_grid_newGridView($view, $nodes, $type) {
  drupal_add_css(drupal_get_path('theme', 'foliage') .'/views-list-newGridView.css');
  $fields = _views_get_fields();
  $content = '<table class="view-grid view-grid-' . $view->name . '">';
 
  // set default count.
  $cols = $view->gridcount ? $view->gridcount : 4;

  $count = 0;
  $total = count($nodes);
  $base_vars = array(
    'view' => $view,
    'view_type' => $type,
  );
  foreach ($nodes as $i => $node) {
    $vars = $base_vars;
    $vars['node'] = $node;
    $vars['count'] = $i;
    $vars['stripe'] = $i % 2 ? 'even' : 'odd';
    if ($count % $cols == 0) {
      $content .= '<tr>';
    }

    foreach ($view->field as $id => $field) {
      $name = $field_names[$id];
      $vars[$name] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
      if (isset($field['label'])) {
        $vars[$name . '_label'] = $field['label'];
      }
    }
    $items[] = _phptemplate_callback('views-list-newGridView', $vars);
    $content .= "<td class='view-grid-item'><div class='view-item view-item-$view->name'>$items</div></td>\n";
    $count++;
    if ($count % $cols == 0 || $count == $total) {
      $content .= '</tr>';
    }
  }
  $content .= '</table>';
  if ($content) {
    return $content;
  }
}

subscribe

Jerimee - January 16, 2009 - 02:54

similar problem here

 
 

Drupal is a registered trademark of Dries Buytaert.