Hi, I am wondering if it is possible to display a view underneath an exising node. E.g. on each "client" page, have a description of the client, and below that, a view of all "job" nodes that relate to that client.

Comments

patrickharris’s picture

$output = views_build_view('embed', views_get_view('name_of_my_view'), $view_args, true, $limit);

ericfoy’s picture

Could you expound on this...?

What do you put in there for $view_args? I would like to have an embedded view show up on similar pages, but with a filter set to show different records, based on the value of a given field. Can this be done?

Thanks,
-eric

Chris Gillis’s picture

I found this page: http://drupal.org/node/47417

My code goes like this:

$view_args = array('2'); //Node id of client page
$view_name = 'Jobs'; //name of view
$limit = 10; // number of returns
echo views_build_view('embed', views_get_view($view_name), $view_args, FALSE, $limit);

The following page describes what the variables passed to the function mean:
http://drupal.org/node/70145

and this page gives a good overview of arguments:
http://drupal.org/node/54455

beauregard’s picture

I tried to use the code above and I get this error:
Fatal error: Only variables can be passed by reference in /home/httpd/vhosts/....../includes/common.inc(1175) : eval()'d code on line 5

I did look around in some other posts but did not find a solution.

Thanks for any hint,
André

inforeto’s picture

<?php
$view_args = array('2'); //Node id of client page
$view_name = 'Jobs'; //name of view
$limit = 10; // number of returns
$view_aux = views_get_view($view_name);
echo views_build_view('embed', $view, $view_aux, FALSE, $limit);
?>

I got that error and solved it by moving views_get_view() out of view_build_view().
That may not be the case everytime, a few of my tries had syntax issues.

beauregard’s picture

great, this worked! Thanks.
Just 1 correction: The parameters $view_aux and $view_args in the views_build_view statement are corrected like this:

<?php
$view_args = array('2'); //Node id of client page
$view_name = 'jobs'; //name of view
$limit = 10; // number of returns
$view_aux = views_get_view($view_name);
echo views_build_view('embed', $view_aux, $view_args, FALSE, $limit);
?>
.carey’s picture

This is great.

How would I change this to not include the most recent article (as in the first story in a descending list)?