Skip navigation


6 node.module node_build_content($node, $teaser = FALSE, $page = FALSE)
7 node.module node_build_content($node, $view_mode = 'full', $langcode = NULL)

Builds a structured array representing the node's content.

The content built for the node (field values, comments, file attachments or other node components) will vary depending on the $view_mode parameter.

Drupal core defines the following view modes for nodes, with the following default use cases:

  • full (default): node is being displayed on its own page (node/123)
  • teaser: node is being displayed on the default home page listing, on taxonomy listing pages, or on blog listing pages.
  • rss: node displayed in an RSS feed.

If search.module is enabled:

  • search_index: node is being indexed for search.
  • search_result: node is being displayed as a search result.

If book.module is enabled:

  • print: node is being displayed in print-friendly mode.

Contributed modules might define additional view modes, or use existing view modes in additional contexts.


$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.

4 calls to node_build_content()


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


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

  // Remove previously built content, if exists.
  $node->content = array();

  // The 'view' hook can be implemented to overwrite the default function
  // to display nodes.
  if (node_hook($node, 'view')) {
    $node = node_invoke($node, 'view', $view_mode, $langcode);

  // Build fields content.
  // In case of a multiple view, node_view_multiple() already ran the
  // 'prepare_view' step. An internal flag prevents the operation from running
  // twice.
  field_attach_prepare_view('node', array($node->nid => $node), $view_mode, $langcode);
  entity_prepare_view('node', array($node->nid => $node), $langcode);
  $node->content += field_attach_view('node', $node, $view_mode, $langcode);

  // Always display a read more link on teasers because we have no way
  // to know when a teaser view is different than a full view.
  $links = array();
  $node->content['links'] = array(
    '#theme' => 'links__node', 
    '#pre_render' => array('drupal_pre_render_links'), 
    '#attributes' => array('class' => array('links', 'inline')),
  if ($view_mode == 'teaser') {
    $node_title_stripped = strip_tags($node->title);
    $links['node-readmore'] = array(
      'title' => t('Read more<span class="element-invisible"> about @title</span>', array('@title' => $node_title_stripped)), 
      'href' => 'node/' . $node->nid, 
      'html' => TRUE, 
      'attributes' => array(
        'rel' => 'tag',
        'title' => $node_title_stripped,
  $node->content['links']['node'] = array(
    '#theme' => 'links__node__node', 
    '#links' => $links, 
    '#attributes' => array('class' => array('links', 'inline')),

  // Allow modules to make their own additions to the node.
  module_invoke_all('node_view', $node, $view_mode, $langcode);
  module_invoke_all('entity_view', $node, 'node', $view_mode, $langcode);