When using Drupal 5.7 you can insert views into nodes using the code

<?php
//load the view by name
$view = views_get_view('sample_view');
//output the view
print views_build_view('embed', $view);
?>

This doesn't seem to work in v6.2 anymore. Does anybody know how you have to modify the code to get this working in D6? Help would be apprediated! Thanks a lot in advance.

Comments

mooffie’s picture

see views_embed_view().

rickardl’s picture

from an example i found:

<?php
  $output = views_embed_view('name of view', $display_id = 'default', $arg1, arg2, ...);
?>

how do you take out items from the embeded view? tried to take a title field as an argument but it didnt work

$output = views_embed_view('name of view', $display_id = 'default', $fields->title);
mooffie’s picture

I don't understand how 'take out' and 'take as' can coincide. I'd suggest you create a new 'display' in your view with some items 'taken out' and tell views_embed_view, by the $display_id parameter, to use this display.

rickardl’s picture

it was a great idea..
however 'Fields' doesnt seem to be unique for each 'display'

i added two 'displays' called 'Title' and 'Body'
In 'Title' i created a field 'Node: Title'
changed to display 'Body' and added 'Node: Body'
Saved, and looked through all displays.. both 'Node: Title' and 'Node: Body' was in all of them..

can this be changed so every Display is unique? i thought that was the point with different 'displays'..

mooffie’s picture

however 'Fields' doesnt seem to be unique for each 'display'

Click the 'Override' button to make them unique (you see this button after you click the 'Fields' header.)

i thought that was the point with different 'displays'..

That's true, settings in different 'displays' can be made independent. The 'Override' vs 'Default' behaviour is explained in the 'What are overrides?' section in the online help.

Cyclist72’s picture

Thanks a lot for your help, it works perfectly now!