4.6.x node.php hook_view(&$node, $teaser = FALSE, $page = FALSE)
4.7.x node.php hook_view(&$node, $teaser = FALSE, $page = FALSE)
5.x node.php hook_view($node, $teaser = FALSE, $page = FALSE)
6.x node.php hook_view($node, $teaser = FALSE, $page = FALSE)
7.x node.api.php hook_view($node, $view_mode, $langcode = NULL)

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.

$teaser: Whether we are to generate a "teaser" or summary of the node, rather than display the whole thing.

$page: Whether the node is being displayed as a standalone page. If this is TRUE, the node title should not be displayed, as it will be printed automatically by the theme system. Also, the module may choose to alter the default breadcrumb trail in this case.

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 in $node->content, rather than directly manipulating $node->body and $node->teaser. The format of this array is the same used by the Forms API. As with FormAPI arrays, the #weight property can be used to control the relative positions of added elements. If for some reason you need to change the body or teaser returned by node_prepare(), you can modify $node->content['body']['#value']. Note that this will be the un-rendered content. To modify the rendered output, see hook_nodeapi($op = 'alter').

For a detailed usage example, see node_example.module.

Related topics

8 functions implement hook_view()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

aggregator_view in modules/aggregator/aggregator.admin.inc
Displays the aggregator administration page.
blog_view in modules/blog/blog.module
Implementation of hook_view().
node_page_view in modules/node/node.module
Menu callback; view a single node.
node_view in modules/node/node.module
Generate a display of the given node.
poll_view in modules/poll/poll.module
Implementation of hook_view().

... See full list

1 invocation of hook_view()
user_build_content in modules/user/user.module
Builds a structured array representing the profile content.

File

developer/hooks/node.php, line 410
These hooks are defined by node modules, modules that define a new kind of node.

Code

function hook_view($node, $teaser = FALSE, $page = FALSE) {
  if ($page) {
    $breadcrumb = array();
    $breadcrumb[] = l(t('Home'), NULL);
    $breadcrumb[] = l(t('Example'), 'example');
    $breadcrumb[] = l($node->field1, 'example/' . $node->field1);
    drupal_set_breadcrumb($breadcrumb);
  }
  $node = node_prepare($node, $teaser);
  $node->content['myfield'] = array(
    '#value' => theme('mymodule_myfield', $node->myfield),
    '#weight' => 1,
  );
  return $node;
}

Comments

splash112’s picture

Just took me 2 hours to find out this function will not work on non-node modules.
Use hook_nodeapi() "view" instead.

doublejosh’s picture

Curious what "non-node modules" means? Perhaps modules that create content types? Do we need to register some kind of function to get this hook enabled?

We need to user hook_view rather than hook_nodeapi for conflict reasons.

andrefy’s picture

Thanks man, this same me a lot of time, I am glad I see you post, it seems than any of the hook_nodes works for non-node modules, It didn't work for the hook_insert, hook_update, hook_view, hook_delete