Faves for this Web page

  • mike - Mar 28 2008 | drupal, views, database

    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.

    • mike - Mar 30 2008

      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.

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.
Rate It

Separate each email address with a comma.
WE DO NOT SPAM | Please read our privacy policy.

Related Content from Around Faves

database

VIEW ALL

sql server

VIEW ALL