Recent blog posts
Reverse NodeReference Block
amariotti — Thu, 10/02/2008 - 09:18
One thing that I was trying to do for a while on my work website was create a block that contained a list of nodes that reference the current node. At that time I had searched in a bunch of places, but didn't know exactly what I was searching for. It so happens that it's actually a really easy views arguement.
What I was trying to do was show a list of the jobs available that are related to the current Program Page that they were on. For example, if they were on the Welding program page they would see a list in a block of the jobs on the job board that have been referenced to that program. So they would see welding related jobs that would be applicable to them!
Back when we had the idea I was too involved in a million other things on the site that it was secondary. I finally had some time yesterday to toy with it. Here's what I came up with:
Set up your Views Block as you would any other views block. It my case I added the "node:title" field, and that was it. You'll want to make sure to set up any filters that you need so you get the list you want in the first place. Again, in my case I was filtering my nodes to the "external_job" content type, but you may want all of the nodes to be displayed. Now, here's where the customization comes into play: under Arguments you need to select the CCK NodeReference field that you'd like to be the controller. Lastly, enter the following in your Argument Handling Code field:
$args[0] = arg(1);Now you're done! Save it and then display it on the pages you'd like.
Special Note: You'll notice in the screenshot that my block has multiple blocks organized using tabs. This was done using the magic_tabs module that I discussed here.
- amariotti's blog
- 3081 reads
