Recent blog posts
Displaying CCK Data only in a Block (vs. in the node content) [UPDATED]
amariotti — Tue, 04/22/2008 - 14:51
I had a challenge that I wanted to share on my blog, so here it is. For my job I'm creating a new website with a page for each Program that we offer (i.e. Welding, Medical Assisting). There is a set of quick facts that need to be associated with each program, but only be displayed in a block in the sidebar. These include information that might be most important to potential students.
My original thought was, that views would be the best way to go. I would just create a block with the fields that I wanted, and it would display based on the NID on the program page they were on. While that sounded really easy, it actually wasn't as easy as that. The biggest trick was figuring out what Views Argument to use to tell it to check the NID first, then display the information. The attached .txt file is the views argument that ended up working.

Drupal 5 Users The attached text file is the argument your paste into your view.
Drupal 6 Users from Andrew Chavez
In D6 + Views 2, set up a fields-type view with an Nid argument. Set what you want shown in the block as your fields. In the argument, under "Actions to take if argument is not present:" choose "Provide default argument." Choose "Node ID from URL" and customize the rest of the argument as usual.
Drupal 6 Walkthrough
Since it would be a little better with screenshots I thought that I would add some screenshots in here to make life easier for the 5 people that actually read my blog.
- Create your view. Make sure that you select "Node" as your view type as shown below

- Change the basic settings on your view. Mainly just the Items to display to 1, which shouldn't matter because there should only be one nid returned.
- Add your fields that you wish to display in your block. For this example I added Node:Comment Count and Node:Updated Time. This could be valuable for sites that have lots of comments with nodes that get update regularly.

- Add an Argument to your view by clicking the + button next Arguments. Then select Node:NID from the list. When your options come up select the options shown in the screenshot below:

- Now your views setting page should look like this.

- Be sure and add a "Block" display to your view so you will have the option of selecting it from your blocks admin page and voila!

And there you have it! Any questions or comments regarding my walkthrough? Contact me!
| Attachment | Size |
|---|---|
| views_d5.txt | 122 bytes |
- amariotti's blog
- 11221 reads
