I have a requirement were I wanted to insert few values depending on whether the node is of type 'news', but when I try to do that with the following code, its seems not working, Could someone help with the code,
function hook_exit() {
if (isset($node) && $node->type == 'event') {
print_r('This is an event');
}
}
According to the Drupal 7 API Reference for hook_exit:
This hook MUST NOT print anything because by the time it runs the response is already sent to the browser.
If you'd like to add information to nodes as they're loaded from the database by Drupal, try using hook_node_load. For example:
function yourmodule_node_load($nodes, $types)
{
foreach ($nodes as $node)
{
// To add or override a node attribute
$node->myvar = "Value";
// To print some data from the node
print_r($node->title);
}
}