How to update header text in hook_views_pre_render I have a view with a header of type "Global: Unfiltered text" that contains the string "Number of drivers: ".

In hook_views_pre_render I count the total number of drivers in each row, and now I want to append this number to the string in my view header.

I did a print_r on the $view object in hook_views_pre_render and found 59 instances of that string.

If it was only a few I would just try replacing each one until it had the desired result - but 59?!?! Too much recursion...

So how do I find which value to update in order to update the text in my view header?
Well the important thing is to narrow down the particular view display you want to affect. Then you can look at the header text later. I have the following similiar code ... you should be able to use views_pre_render fine, I don't use that here:

function MYMODULE_views_post_execute(&amp;$view) {
  if ($view-&gt;name == 'migration_audits') {
    $drupal_nids = array();
    if (count($view-&gt;result)) {
      foreach ($view-&gt;result as $i =&gt; $node) {
        $drupal_nids []= $node-&gt;nid;
      }
    }
   $sql = " ... ";
   $result = db_query($sql, array(':drupal_nids' =&gt; $drupal_nids));
    $output = '';
    foreach ($result as $course) {
      #dpm($course);
      $title = html_entity_decode($course-&gt;course_title, ENT_COMPAT, 'UTF-8');
      $instructors = html_entity_decode($course-&gt;instructor, ENT_COMPAT, 'UTF-8');
      $output .= "&lt;div class=\"entry\"&gt;$course-&gt;quarter $course-&gt;year - $title Instructors:&amp;nbsp;$instructors&lt;/div&gt;";
    }


    $my_values = "&lt;style type=\"text/css\"&gt;div.legacy_values { background-color: pink;} div.legacy_values div.entry { padding-bottom: 5px; }&lt;/style&gt;&lt;div class=\"legacy_values\"&gt;$output&lt;/div&gt;";
    $view-&gt;display['page']-&gt;handler-&gt;handlers['header']['area_1']-&gt;options['content'] = $my_values;
    $view-&gt;display['page']-&gt;handler-&gt;handlers['header']['area_1']-&gt;options['empty'] = 0;
  }
}


You can also do like $view-&gt;display[$view-&gt;current_display] usually as a safe none hard coded approach. Note that the global header regions are given names such as area_1, area_2 etc as a convention by Views. I also tell Views the area is now not empty.