How can I add variables from a preprocessor function to be used in an unformatted view template? The variables I'm adding in my preprocessor function are not visible in the template for the unformatted view I've written. This seems to work fine if the template is formatted (the default).

That is, in template.php I set some variable $foo in the preprocessor…

function themename_preprocess_views_view(&amp;$vars) {
  // Do view-specific preprocessing in here because of http://drupal.org/node/939462
  if ( $vars['view']-&gt;name === "viewname" ) {
    $vars['foo'] = 'bar'; // set $foo to be used in viewname templates
  }
}


…such that I can use it in views-view--viewname.tpl.php, &lt;?php echo $foo; ?&gt;. This works just fine.

However, $foo is undefined in views-view-unformatted--viewname.tpl.php.

Why is this? How can I store the results of my preprocessing in a variable I can then use in the template for my unformatted view?

Doing the preprocessing in a function specific to the unformatted view doesn't work because


such a function, themename_preprocess_views_view_unformatted__viewname(), will not be called due to a bug, and
working around the bug by defining its behaviour in, or calling it from, themename_preprocess_views_view() doesn't work


as above, where I seem to make changes to $vars that should be accessible in all viewname view templates,
nor can it be repeated specifically for the unformatted view templates because there's nothing in $vars that can be used to discriminate the unformatted from the default view.



Any help?
Your problem is that the output for the view is built up from the inside-out.  So, the views-view template already has the processed results from the views-view-unformatted template.

You should just be able to implement a template_preprocess_views_view_unformatted(), and do a manual check:

function mytheme_preprocess_views_view_unformatted(&amp;$variables) {
  $view = $variables['view'];

  if ($view-&gt;name == 'viewname') {
    $variables['foo'] = 'bar';
  }
}


I don't typically use unformatted output, but I do it somewhat often at the field level.