The folling code gives me a view by name.

$view = views_get_view('viewname');

How do I get the nodes from here?

I don't want some function to automatically print out the contents of the view. I want the nodes (as an array), so I can do the following:

foreach($nodes as $node) {
echo $node->title; // or whatever I want to do with the node
}

Comments

Mattias Holmqvist’s picture

Views2 Documentation (not much help)
http://groups.drupal.org/node/10129

My view returns 2 nodes to it's default node-view-myView.tpl.php.

So I load the same view.
$view = views_get_view('myView');

It gets loaded cause it's not null and echo $view->name prints 'myView'.

I use the following taken from Views2 documentation:

foreach ($view->result as $result) { // $view->result is an array size 1.
foreach ($view->field as $id => $field) { // $view->field is an array size 0.
if (!empty($view->field[$id]['handler'])) {
$view->field[$id]['handler']->pre_render($view->result);
// somewhere here I want to load the node with "node_load($someId);"
// but none of the variables echoes anything.
}
}
}

So, $view->result is an array size 1 and $view->field is an array size 0.
Now where are my 2 nodes?

It doesn't help me to get answers related to how you do it in Drupal 5.
Can someone using Drupal 6 Views 2 tell me how to get my nodes from my view?

Mattias Holmqvist’s picture

Status: Active » Fixed

The solution is:

echo views_embed_view($name, $display_id = 'default');
(Easy embed, http://groups.drupal.org/node/10129)

This embeds the other view right into the current one.
As long as the two views (or more) don't need to know of each other there is no reason not to do it like this.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.