function view::render

3.x view.inc view::render($display_id = NULL)
2.x view.inc view::render($display_id = NULL)

Render this view for display.

File

includes/view.inc, line 850
view.inc Provides the view object type and associated methods.

Class

view
An object to contain all of the data to generate a view, plus the member functions to build the view query, execute the query and render the output.

Code

function render($display_id = NULL) {
  $this->execute($display_id);

  // Check to see if the build failed.
  if (!empty($this->build_info['fail'])) {
    return;
  }

  init_theme();

  $start = views_microtime();
  if (!empty($this->live_preview) && variable_get('views_show_additional_queries', FALSE)) {
    $this->start_query_capture();
  }

  // Check for already-cached output.
  if (!empty($this->live_preview)) {
    $cache = FALSE;
  }
  else {
    $cache = $this->display_handler->get_cache_plugin();
  }
  if ($cache && $cache->cache_get('output')) {
    vpr('Used cached output');
  }
  else {
    if ($cache) {
      $cache->cache_start();
    }

    // Initialize the style plugin.
    $this->init_style();

    $this->style_plugin->pre_render($this->result);

    // Let modules modify the view just prior to rendering it.
    foreach (module_implements('views_pre_render') as $module) {
      $function = $module . '_views_pre_render';
      $function($this);
    }

    // Let the theme play too, because pre render is a very themey thing.
    $function = $GLOBALS['theme'] . '_views_pre_render';
    if (function_exists($function)) {
      $function($this);
    }

    // Give field handlers the opportunity to perform additional queries
    // using the entire resultset prior to rendering.
    if ($this->style_plugin->uses_fields()) {
      foreach ($this->field as $id => $handler) {
        if (!empty($this->field[$id])) {
          $this->field[$id]->pre_render($this->result);
        }
      }
    }
    $this->display_handler->output = $this->display_handler->render();
    if ($cache) {
      $cache->cache_set('output');
    }
  }

  if ($cache) {
    $cache->post_render($this->display_handler->output);
  }

  // Let modules modify the view output after it is rendered.
  foreach (module_implements('views_post_render') as $module) {
    $function = $module . '_views_post_render';
    $function($this, $this->display_handler->output, $cache);
  }

  // Let the theme play too, because post render is a very themey thing.
  $function = $GLOBALS['theme'] . '_views_post_render';
  if (function_exists($function)) {
    $function($this, $this->display_handler->output, $cache);
  }

  if (!empty($this->live_preview) && variable_get('views_show_additional_queries', FALSE)) {
    $this->end_query_capture();
  }
  $this->render_time = views_microtime() - $start;

  return $this->display_handler->output;
}