You are here

function template_preprocess_node in Drupal 6

Same name and namespace in other branches
  1. 8 core/modules/node/node.module \template_preprocess_node()
  2. 7 modules/node/node.module \template_preprocess_node()
  3. 9 core/modules/node/node.module \template_preprocess_node()
  4. 10 core/modules/node/node.module \template_preprocess_node()

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

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;
}