1 comment.module comment_preprocess_node(&$variables)

Prepares variables for comment.tpl.php


$variables: An array containing the following arguments:

  • $node
  • $view_mode
  • $page

See also



core/modules/comment/comment.module, line 2270
Enables users to comment on published content.


function comment_preprocess_node(&$variables) {
  $node = $variables['node'];
  $node_type = node_type_get_type($node->type);

  // Only append comments when we are building a node on its own node detail
  // page. We compare $node and $page_node to ensure that comments are not
  // appended to other nodes shown on the page, for example a node_reference
  // displayed in 'full' display mode within another node.
  if ($node->comment && $variables['view_mode'] == 'full' && node_is_page($node) && empty($node->in_preview)) {
    $variables['comments'] = comment_node_page_additions($node);
    $variables['comment_display_mode'] = $node_type->settings['comment_mode'];
  // Simplify the variables if there are no comment parts.
  if (empty($variables['comments']['comments']) && empty($variables['comments']['comment_form'])) {
    $variables['comments'] = FALSE;