context-sensitive embedded views | drupal.orgFirst Faved : Mar 28 2008 by mikeFaved : 1 time with noteViewed : 21 timesFave It!
Faves for this Web page
I'm trying to embed a (static) view in a Drupal node (I want to show the employees of a company inside the company node).
This is the first time I've found that there seems to be no Drupal module for doing a common action like this. The two related modules (Insert View and View Field) allow the user to embed a view at edit time of the node. I just want this view statically defined for the node.
It seems pretty insane to have to embed custom PHP for each node that you want to contain a sub-view.
Already a user? Sign In
Add a Fave for this Web page
- What happens when I press Publish?
- Your Fave for this Web page gets shared with the Faves community. You can access it at any time by selecting "My Faves" from the menu above.
- Why do you ask for my email address?
- We use your email address to create an account, so you can easily find your Fave again at a later time.
Related Content from Around Faves
database
-
You can see a map of all the Seattle based Startups in TechCrunch's startup database.
Faves and RescueTime are both on the map.
1 FaverViewed: 2 Times - guido - Feb 22 20094 FaversViewed: 8 Times
- adam - Jun 26 20061 FaverViewed: 72 Times

There is a small amount of PHP required to do this. The basic technique is to create a sub-view which you will display when the parent node is displayed. But, in order to get the correct filter, you have to add an "argument" to the sub-view using the CCK reference node field to the parent node. Since this is a numeric arguement, you have to write a small amount of PHP while copies the node id (nid) to the view argument variable (Note: Arguments are really just parameterized Filters who's values can come from the current URL via string matching or from custom PHP as described here).
- Admin/Views:
- Create a Block-type view for your sub-view.
- Add any fields or view type you would normally use.
- Add an Argument of type Node Reference: <Parent Node Type>
- In the Argument Handle Code paste in:
----------------
if ($view->build_type == 'block' && arg(0) == 'node' && is_numeric(arg(1))) {
$args[0] = arg(1);
}
return $args;
----------------
- Save
- Admin/Blocks:
- Configure the block to display only on the parent node path (e.g., "companies/*" - assuming you're using pathauto).
It's not that elegant - but it's a very minimal amount of additional PHP code.