Skip navigation
Help

hook_view

6 node.php hook_view($node, $teaser = FALSE, $page = FALSE)
7 node.api.php hook_view($node, $view_mode)

Display a node.

This is a hook used by node modules. It allows a module to define a custom method of displaying its nodes, usually by displaying extra information particular to that node type.

Parameters

$node: The node to be displayed, as returned by node_load().

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

Return value

$node. The passed $node parameter should be modified as necessary and returned so it can be properly presented. Nodes are prepared for display by assembling a structured array, formatted as in the Form API, in $node->content. As with Form API arrays, the #weight property can be used to control the relative positions of added elements. After this hook is invoked, node_view() calls field_attach_view() to add field views to $node->content, and then invokes hook_node_view() and hook_node_view_alter(), so if you want to affect the final view of the node, you might consider implementing one of these hooks instead.

For a detailed usage example, see node_example.module.

Related topics

80 functions implement hook_view()

3 invocations of hook_view()

File

drupal/modules/node/node.api.php, line 1257
Hooks provided by the Node module.

Code

function hook_view($node, $view_mode) {
  if ($view_mode == 'full' && node_is_page($node)) {
    $breadcrumb = array();
    $breadcrumb[] = l(t('Home'), NULL);
    $breadcrumb[] = l(t('Example'), 'example');
    $breadcrumb[] = l($node->field1, 'example/' . $node->field1);
    drupal_set_breadcrumb($breadcrumb);
  }

  $node->content['myfield'] = array(
    '#markup' => theme('mymodule_myfield', $node->myfield), 
    '#weight' => 1,
  );

  return $node;
}