views:

197

answers:

1

I'm trying to produce a page with a list of specific nodes but the node_view returns an empty string.

This is my query:

function events_upcoming() {
  $output = '';
  $has_events = false;

  $res = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'events' AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10));

  while ($n = db_fetch_object($res)) {
    $output .= node_view(node_load($n->nid), 1);

    $has_events = true;
  }

  if ($has_events) {  
    $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
  }

  return $output;
}

hook_menu (part of):

'events/upcoming' => array(
      'title' => t('Upcoming Events'),
      'page callback' => 'events_upcoming',
      'access arguments' => array('access content'),
      'type' => MENU_SUGGESTED_ITEM
    ),

the implementation of hook_view:

function events_view($node, $teaser = false, $page = false) {
  $node = node_prepare($node, $teaser);

  if ($page) {
    // TODO: Handle breadcrump
  }

  return $node;
}

now, if I add a var_dump($node) inside events_view the node is present and I can see the values I want, and if I add a var_dump inside while loop in events_upcoming I also get a node id from the query.

the strange thing is, when I load localhost/events/upcoming I see the pager and nothing else.

I have used the blog.module as a reference, but what am I missing here?

A: 

Here the thread, with a patch in it, and another answer as well from me.

http://drupal.org/node/229411

You can use node_load at each spot you want to do the node_view, but that seems wasteful of your processor.

Checkout the patch, though it's on the core node module.

doublejosh