Using Viewfield Arguments in Views 2

Think of a situation where you have Place nodes,each node representing a Place.

Now you have company nodes, which represent companies.

In company node you have a Node Reference field referring to 'Place' where company resides.

Now I will explain How you can use viewfield module along with cck + view to automatically list "Companies at this location" on each 'Place' Node with out user entering them.

I am no good at explaining so I can give only a rough idea.

1. In the 'Places' Node Type, create a new field of type viewfield name it "Companies at this location".

2.You can see options to select the view to be used and a field for arguments. Set Argument as "%nid" and view as the view you want to use.(In our case view will be one that filters nodeType=Company).

3.Now in arguments of view(not viewfield) set argumentto content-> name of Node Reference field referring to 'Place' in Company node.

4. current nid of open page is passed by viewfield, the view defined by viewfield grabs this nid and checks with argument set in view definintion.


SELECT node.nid AS nid,
node.title AS node_title
FROM node node
LEFT JOIN content_type_company node_data_field_place ON node.vid = node_data_field_place.vid
WHERE (node.type in ('company')) AND (node_data_field_place.field_place_nid = 2)

This can be done in reverse way by creating a multiple field for 'companies' in 'Place' nodes. That can be filtered by using views for nodes that can be referenced.

But this is 1:M relation place:companies. I feel it hard to enter data.

I feel it easier to enter place as we create a Company.

Related Posts by Categories

Widget by Hoctro | Jack Book

0 Responses: