Search code examples
drupaldrupal-viewsdrupal-blocks

Drupal: Content in blocks from node_reference fields?


After only a few weeks of working with Drupal I've come up with a recurring problem, which I don't really have an optimal solution to, so I'm hoping that someone here might be able to give some best practice pointers.

What I have is a region inside my node.tpl.php, which is populated with blocks that display content from two different CCK fields of the type node_reference. This works fine when displaying a single node. The problem appears when I need to use a view.

For example, lets say I have a news listing, and a single news item view. When I display the single news item I can use the news node node_reference field to reference whatever material I would like to have in my sidebar, but when on the news listing view I would like to reference nodes separately. What would be the best practice to solve this?

I'm having a few ideas, but none seem like the logical choice, how would you do?


Solution

  • After reading my question I realize that it was explained pretty badly, so I'll try again, and also tell how I solved it.

    The Problem
    On normal "pages" (when displaying only a single node), I have a sidebar that shows something similar to banners, which are either random, or I can select one or many that should always be displayed on the sidebar. This is solved easily when displaying a single node, using a CCK node_reference field. The problem is when using a View that displays multiple nodes, for example a news listing-

    The Solution
    In my case I could solve this by creating additional fields on my default Page content-type. These fields were called view, display and arguments. In my tpl.php I then embedded the news listing view inside a page, lets call it News. This way I gained great flexibility, and also helps the News page to know where it is located in menu structure.

    Final comments
    I have yet to discover if there are any drawbacks or dangers in doing this way, but if there are, feel free to share them with me :)