Here is a little gotcha about overriding a View in a block on a Zen sub-theme in Drupal 5 that I thought I should write down, and perhaps share.

I am working on a Drupal 5 site, and I am using Views. I NEED to override how a Views generated block is themed, and because blocks only have access to the $content string, and I need to access a node variable, I needed to override the view and send my node information to it.

Fine, there is a great page on how to do just that, and the Views Theme Wizard rocks the Casbah as well. One problem, NOTHING WAS HAPPENING!

Ok, so I banged my head on it for a while until I realized that perhaps my _phptemplate callback was calling back to the wrong place, because it might have expected it to reside in the base theme directory.

BINGO, setting my test views-list-featured_video.tpl.php file into the base Zen directory instantly produced my overridden content. Since we don't want to put things in the Zen directory, I altered the code in my template php to include the sub-theme name so my template.php contains this:

<?php
function phptemplate_views_view_list_featured_video($view, $nodes, $type) {
 
$fields = _views_get_fields();

 
$taken = array();

 
// Set up the fields in nicely named chunks.
 
foreach ($view->field as $id => $field) {
   
$field_name = $field['field'];
    if (isset(
$taken[$field_name])) {
     
$field_name = $field['queryname'];
    }
   
$taken[$field_name] = true;
   
$field_names[$id] = $field_name;
  }

 
// Set up some variables that won't change.
 
$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';
    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('ice/views-list-featured_video', $vars);
  }
  if (
$items) {
    return
theme('item_list', $items);
  }
}
?>

The part to make note of is right there towards the bottom where I include my sub-theme name, ICE:


$items[] = _phptemplate_callback('subthemename/views-list-featured_video', $vars);

Without that nothing happens. With it, everything is rainbows and magical pixie horses ;)

Thanks Man

Thanks for posting mate. You saved me a whole bunch of time with this.

All the best for the New Year.

This is actually documented in the themer's guide

http://drupal.org/node/220111

Note that the method presented here prevents you from having to hard-code the subtheme name. And there's one more modification needed beyond just specifying the path correctly…

Just needed this the other day!

Amazing

Drupal 5 views were more advanced I see.

Powered by Drupal, an open source content management system