Sometimes you want to move a cck field out of the main content area and put it in a region like a left or right sidebar.
There are some options for this that include a number of modules and perhaps panels, but I wanted a lighter weight solution and the solution is: CCK and Views!
My goal here was to have a related content block for a given node of type page. So:
Step 1: create a cck node reference field that references other page nodes (or any other content type you'd like to use).
Step 2: create a view called related_pages.
A. Add filters for node: published and node: type page
B. Add a views argument for Node:nid with settings: Action to take if argument is not present: Node ID from URL, Validator: node (types page, Argument type: Node ID, Action to take if argument does not validate: Hide View/ Page Not Found).
C. Add the content: related_pages field to the view's field. Create a block display and title it to your liking.
Step 3. Go to admin -> build -> blocks and located the related_pages:Block block. Add it to a sidebar region (or any other region you'd like). Optionally, restrict the block to show only on specific pages.
Whoila! Your CCK fields are now in the sidebar region.
I've attached CCK fields and Views definitions you can easily import below.
| Attachment | Size |
|---|---|
| related_pages_field_cck.txt | 3.24 KB |
| related_pages_view.txt | 3.76 KB |
When You Are Engulfed in Flames
David Sedaris
Drupal 6 JavaScript and jQuery
Matt Butcher
Learning Drupal 6 Module Development
Matt Butcher
Front End Drupal: Designing, Theming, Scripting
Konstantin Käfer
Neuromancer (Sprawl Trilogy, #1)
William Gibson
This is great thanks!
Geoff thanks for this tutorial, it is just what I needed and have been searching for, for a while.
I didn't get view working using the description above, but once I imported the attachments everything worked o.k.
I think what was missing is the widget type you need to set for the for the node reference field. I had selected 'selection list' and I noticed in the imported version it was set to auto completed text. Also, does the view need to be created prior to adding the CCK field, as the node reference field required a view to use right?
- I just had one question. How can I hide the block if no content is returned?
Many thanks again for the post!