function template_preprocess_node

7.x node.module template_preprocess_node(&$variables)
6.x theme.inc template_preprocess_node(&$variables)

Process variables for node.tpl.php

Most themes utilize their own copy of node.tpl.php. The default is located inside "modules/node/node.tpl.php". Look in there for the full list of variables.

The $variables array contains the following arguments:

  • $node
  • $teaser
  • $page

See also

node.tpl.php

File

drupal-6.x/includes/theme.inc, line 1983
The theme system, which controls the output of Drupal.

Code

function template_preprocess_node(&$variables) {
  $node = $variables['node'];
  if (module_exists('taxonomy')) {
    $variables['taxonomy'] = taxonomy_link('taxonomy terms', $node);
  }
  else {
    $variables['taxonomy'] = array();
  }

  if ($variables['teaser'] && $node->teaser) {
    $variables['content'] = $node->teaser;
  }
  elseif (isset($node->body)) {
    $variables['content'] = $node->body;
  }
  else {
    $variables['content'] = '';
  }

  $variables['date'] = format_date($node->created);
  $variables['links'] = !empty($node->links) ? theme('links', $node->links, array('class' => 'links inline')) : '';
  $variables['name'] = theme('username', $node);
  $variables['node_url'] = url('node/' . $node->nid);
  $variables['terms'] = theme('links', $variables['taxonomy'], array('class' => 'links inline'));
  $variables['title'] = check_plain($node->title);

  // Flatten the node object's member fields.
  $variables = array_merge((array) $node, $variables);

  // Display info only on certain node types.
  if (theme_get_setting('toggle_node_info_' . $node->type)) {
    $variables['submitted'] = theme('node_submitted', $node);
    $variables['picture'] = theme_get_setting('toggle_node_user_picture') ? theme('user_picture', $node) : '';
  }
  else {
    $variables['submitted'] = '';
    $variables['picture'] = '';
  }
  // Clean up name so there are no underscores.
  $variables['template_files'][] = 'node-' . $node->type;
}