8.5.x node.module node_view(NodeInterface $node, $view_mode = 'full', $langcode = NULL)
8.0.x node.module node_view(NodeInterface $node, $view_mode = 'full', $langcode = NULL)
8.1.x node.module node_view(NodeInterface $node, $view_mode = 'full', $langcode = NULL)
8.2.x node.module node_view(NodeInterface $node, $view_mode = 'full', $langcode = NULL)
8.3.x node.module node_view(NodeInterface $node, $view_mode = 'full', $langcode = NULL)
8.4.x node.module node_view(NodeInterface $node, $view_mode = 'full', $langcode = NULL)
8.6.x node.module node_view(NodeInterface $node, $view_mode = 'full', $langcode = NULL)
4.6.x node.module node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE)
4.7.x node.module node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE)
5.x node.module node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE)
6.x node.module node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE)
7.x node.module node_view($node, $view_mode = 'full', $langcode = NULL)

Generates an array for rendering the given node.

Parameters

$node: A node object.

$view_mode: View mode, e.g. 'full', 'teaser'...

$langcode: (optional) A language code to use for rendering. Defaults to the global content language of the current request.

Return value

An array as expected by drupal_render().

12 calls to node_view()
book_node_export in modules/book/book.module
Generates printer-friendly HTML for a node.
FieldUIManageDisplayTestCase::assertNodeViewTextHelper in modules/field_ui/field_ui.test
Asserts that a string is (not) found in the rendered nodein a view mode.
ImageFieldDefaultImagesTestCase::testDefaultImages in modules/image/image.test
Tests CRUD for fields and fields instances with default images.
NodeEntityViewModeAlterTest::testNodeViewModeChange in modules/node/node.test
Create a "Basic page" node and verify its consistency in the database.
NodeEntityViewModeAlterTest::testNodeViewModeChangeHiddenField in modules/node/node.test
Tests fields that were previously hidden when the view mode is changed.

... See full list

1 string reference to 'node_view'
trigger_node_view in modules/trigger/trigger.module
Implements hook_node_view().

File

modules/node/node.module, line 1330
The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern.

Code

function node_view($node, $view_mode = 'full', $langcode = NULL) {
  if (!isset($langcode)) {
    $langcode = $GLOBALS['language_content']->language;
  }

  // Populate $node->content with a render() array.
  node_build_content($node, $view_mode, $langcode);
  $build = $node->content;

  // We don't need duplicate rendering info in node->content.
  unset($node->content);
  $build += array(
    '#theme' => 'node',
    '#node' => $node,
    '#view_mode' => $view_mode,
    '#language' => $langcode,
  );

  // Add contextual links for this node, except when the node is already being
  // displayed on its own page. Modules may alter this behavior (for example,
  // to restrict contextual links to certain view modes) by implementing
  // hook_node_view_alter().
  if (!empty($node->nid) && !($view_mode == 'full' && node_is_page($node))) {
    $build['#contextual_links']['node'] = array(
      'node',
      array(
        $node->nid,
      ),
    );
  }

  // Allow modules to modify the structured node.
  $type = 'node';
  drupal_alter(array(
    'node_view',
    'entity_view',
  ), $build, $type);
  return $build;
}

Comments

hefox’s picture

The $links parameter has been removed in 7.

To disable links, looks like need to do something akin to below (untested)

$build = node_view( ...);
$build['links']['#access'] = FALSE;
casivaagustin’s picture

This is a sample how to render a node using node_view

<?php
  $node = node_load($nid);
  $node_view = node_view($node);
  $rendered_node = drupal_render($node_view);
  echo $rendered_node;
?>
orjantorang’s picture

Thanks, and to just get the node body without the header link, View/Edit and and footer links, just render the 'body' item:

<?php
...
$rendered_node = drupal_render($node_view['body']);
...
?>
wasid’s picture

@casivaagustin
Thanks for your simple example!

Michael-IDA’s picture

Couple other examples using more relevant variable names.

Yeah, yeah, CDO much? :)

Check if user has permission to view it:

<?php
  $nid = 10169;
  $node = node_load($nid);
  if ( node_access('view', $node) ) {
    $node_view = node_view($node);
    $rendered_body = drupal_render($node_view['body']);
    echo $rendered_body;
  }
?>

Toss in a login block and some CAPTCHA to the bottom of the page:

<?php
  $nid = 10169;
  $node = node_load($nid);
  $node_view = node_view($node);
  $rendered_body = drupal_render($node_view['body']);
  echo $rendered_body;
  $form = drupal_get_form('user_login_block');
  unset($form['links']);
  if (module_exists('captcha')) {
    $form['my_captcha_element'] = array(
      '#type' => 'captcha',
    );
  }
  echo render($form);
?>