Hello! I am attempting to use a Viewfield to insert a view using an argument for a nodereference field. So, node ABC will include a Viewfield for view XYZ. View XYZ contains nodes that have a nodereference field. For node ABC, the view should display the nodes for which their nodereference field equals node ABC. I've gotten as far as adding the "nodereference" Argument Type within the view but I can't figure out from there if I need some special Argument Handling Code as well or what should be used as the argument in the Viewfield.

Can anyone offer some specific guidance?

Comments

michaelfavia’s picture

if you find me in IRC i can explain this better for you but you are on the right track. You need to pass the NID of the nodereference field instead of %nid do to what i think you want to do. this can be done in the phpcode section under default value (and you can hide the whole affair as well so you users dont have to see the nonsense of selecting vierws, etc.)

WISEOZ’s picture

Thanks very much for the offer to help! I actually finally figured it out.

WISEOZ’s picture

Status: Active » Closed (fixed)
shaman365’s picture

Hello! I don't know if I'm posting in the right area....but I think this is what I am trying to do too... I have a view that displays the nodes from a nodreference field and for the life of me I can't figure out how to have the nodes in the array show up as a non integer value. I basically need the actual node value to show up in the views service.

Here's how my view shows up in the views service:

[field_trackitem] => Array
(
[0] => Array
(
[nid] => 9
)

[1] => Array
(
[nid] => 12
)

)

I need those [nid]'s to show that actual node values. I'm building an flash mp3 player application that collects this data from this view. I just can't figure this out. Any help is very appreciated. Thanks!

scottrigby’s picture

Version: 5.x-1.2 » 6.x-1.x-dev
Status: Closed (fixed) » Active

Hi michaelfavia & WISEOZ,

I'm trying to do what it sounds like you're asking - using nodereference to filter a view - and I'm running into difficulty (maybe in my configurations) so it'd be great if I could ask your help.

I've seen some documentation - like this http://drupal.org/node/289738 - but it doesn't seem to be working for me.

What i'm doing is using a viewfield in node-type-x to show a list of node-type-y. But I want to limit that using a noderefence, so site editorys can choose which node-type-y show in that list. I can't yet seem to get it to work in drupal 6 yet.

Details:
I'm using cck to make 2 node-types (for this proof of concept)...
for now I'm calling them node-type x & y
in each Node-type-x, I want to show a list of nodes (this list is a selection of type-y nodes)
I'm using views2 to create the list (this is in drupal6)
and I'm using viewfield to embed the view (instead of doing it in the .tpl file or something)
so far, all works ok --
except the same list shows on every node of type-x... but now I want to make that list specific to the node...
I'm trying to use a nodereference field to allow the site editor to choose specific y-nodes to filter the list, instead of showing all y-nodes in the list.

Thanks in advance for your advice –
:) Scott

WISEOZ’s picture

Here's how mine is set up ...

· Check the "Provide Page View" checkbox

· Include a "$arg" in your URL. My URL looks like this: node/$arg/stages

· I use a View Type of "Full Nodes". You can select certain fields as well.

· For Arguments, I have "Node Reference: Event Reference (field_eventreference)" which is the name of the node reference field I am using for my argument. This is where you would include your node reference field. Leave with default settings.

· I apply a Published equals "Yes" and a Node: Type filter to narrow down my results as well.

And, that's it! I actually have things called Stage nodes which reference Event nodes. This approach works just fine for me. Let me know if it works for you. Good luck!

scottrigby’s picture

Hi WISEOZ,

Under "Relationships" I added my nodereference field as the relationship. There is the option to "require this relationship", which I assume i would need? Otherwise, I have just waht I have now - I see the nodes, but not filtered by the nodereference field (but so far I haven't been able to put all the pieces together to work yet, so I'm 100% sure).

I added the argument "Node: Nid" - and selected my nodereference field as the relationship ('field_promo_select_nid'). I left all other options default.

in views2 it's a little different, right? we can add different displays - ok, so I'm adding a page display now (though, I'm embedding my view, so not sure that's necessary? - anyway doing it to test). Regarding the URL... $arg has changed to % in Views2 apparently (that's what the message says anyway). So I enabled that. However, once I did, my node content no longer showed at all, on any node. SO I had to remove the page view just to see my node content again. :p

This is the farthest I've got – earlier today I asked merlinofchaos on IRC, and he made some suggestions to be sure the issue wasn't with viewfield (looks like it may not be afterall), and then he wasn't sure so suggested I read the tutorial to get a better sense of where I may have gone wrong... but I looked in the documentation linked on the Views project page, and I didn't see any tutorial about this -- have you? :S I'd gladly go that route instead of just asking here, but it's not really possible to test unless I know the expected behavior, and the steps to get there?

Thanks for your response though... I really do need to get this working one way or another (trying to make it easy for the client to select options that will affect the embedded view, otherwise this would not be a problem)... :?

Scott

Gabriel R.’s picture

Status: Closed (fixed) » Active

I'm trying to do the same thing on my site and would like to avoid using SQL in the template. Looking forward to a solution to this.

asak’s picture

subscribing

tindo’s picture

Hi Scott,
I have the same problem as you. I cant seem to get it to work although im now almost sure its the viewfield that is the problem. I added a block display to my view and it works perfectly on the node page which is why i think this is a viewfield problem. Did you ever manage to solve this?

scottrigby’s picture

No I didn't actually - because I decided for this particular site it would work just as well to reverse the procedure.

Now I'm using a nodereference field on my node-type x instead. I'm using a view to select which nodes can be referenced (can select the view under the fieldset 'Advanced - Nodes that can be referenced (View)'). In this case, my needs are simple, so I just made a view that filtered nodes of type y. So now on my node-type x, I have a nodereference field that allows me to select y nodes.

In the display settings for the nodereference field, I can set it to display teasers, which is exactly what I wanted.

I'd like to know if someone gets this solved using a viewfield though... good luck :)

Scott

tindo’s picture

Hi, apparently viewfield excludes the current node by design. Check out http://drupal.org/node/216551. THis is done to prevent an infinite loop. Im assuming you have to muck around with the viewfield module and disable this behaviour. i dont know the consequences of this and am not suggesting it for anyone. Just thot it might help someone who's been going round in circles like me. :)

joemoraca’s picture

I think I am trying to do the same thing as you all seem to be doing. I have 3 content types:
client info -- the parent
client location -- node reference to client info -- so there can be multiple locations per client
client staff -- node reference to client info -- so there can be multiple staff per client

I want the client info content type to display it's fields plus the list of locations and staff that match it.

I created 2 views -- one for client location and one for client staff -- they both have a node reference field to client info as an argument -- the views work fine testing them with the [nid] ... in the url and in the views2 UI.

I added 2 viewfield fields to my client info content type and tried various combinations of viewfield configuration to get it to work ... what I thought "should" work left me with nothing showing on the client info node. Until I left "force default" unchecked ...

Then if I go in to edit a client info node I see a fieldset created by "viewfield" and if I type [nid] in the "Locations (clientlocationnode) arguments:" field and save then my locations show up like I expect.

It would seem based on the UI that using the viewfield configuration when I add the field to my content type I should be able to "force" any node of that content type to pass [nid] to the view without the node editor doing anything.... this would be my "expected behavior" but I have no clue why it doesn't work that way.. but perhaps my long winded explanation will help someone figure this out.

This CCK / Views stuff is really great so working out the bugs is worth the effort

darren oh’s picture

Status: Active » Closed (fixed)

The original issue is closed. The remaining problem is being discussed in issue 165321.

dimon00’s picture

Status: Active » Closed (fixed)

I know that this thread is closed but I wished to achieve the same result in D7 and started from here.
I hope to spare a couple of hours of tests to others.

I have two node types: Product and Subproduct.
Subproduct has a reference field to Product.

I want to add a view in Product which shows a list of Subproducts referring to the product itself.

How I did it:
1. I created the view with the parameters I needed.
2. in the context I placed "Content: Product:target_id " which is the Subproduct field referring to product.
3. Saved the view
4. Modified the Product node adding a viewfield,
5. the viewfield contains the view I created in step 1 8I don't know the difference between Master and Page so I used Master),
6. under default value -> arguments place [node:nid]
7. save and set the value of the field for the Product node alredy created (the new ones take the dafault value).

Hope it helps.