I have a nodereference field in a custom content type.
In Views: I want to be able to output a link like this:
node/[field_custom_noderef_nid]/my_custom_string

The problem is that instead of outputting the nid of the referenced node, the [field_custom_noderef_nid] token is outputting the title of the referenced node...

Same applies to userreference module.

But maybe I'm missing something here... ?

CommentFileSizeAuthor
#16 relationship-delta.JPG40.34 KBKimberley_p
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

adam1’s picture

I am struggeling with the same problem ...

markus_petrux’s picture

Category: task » support
Status: Active » Fixed

This is because Views is giving you the rendered output of the field in the replacement pattern.

To solve this, instead of using "Rewrite the output of this field" option of the field in Views, you need to provide a new formatter for nodereference fields, and then you can choose it from the "Format" option of the field in Views.

To create more formatters for noderef fields, see these examples:

http://drupal.org/project/cck_formatters
http://drupal.org/project/nodereference_formatters

Another approach: use a Views custom field - PHP code:

http://drupal.org/project/views_customfield

adam1’s picture

Thank you very much, markus. i will try out the alternatives.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

prabhakarsun’s picture

Easy way;

1. Add a relationship of required node reference.
2. Add a Node:Nid field with this relationship,rewrite it's output as you wish.

dag_helstad’s picture

@prabhakarsun: Thanks! I would *never* have figured out that by myself :)

/Dag

m4olivei’s picture

@prabhakarsun: The only issue with your solution is when the node reference field can have multiple values. When you have multiple values, adding the relationship and adding the node id of the relationship will produce a row for every value of the node reference field. What then? This is where I find myself.

What I would like is to simply add the node reference field to my fields which would give me a list of the node id's referenced, which I ca then use and theme how ever I want in template files. Do I have to write a custom formatter in that case?

Thanks,
~Matt

m4olivei’s picture

Hey,

I figured out what to do in my situation. What I ended up doing was to set the formatter to 'Teaser' on the node reference in the view, and then used a template file for that node type to render it how I wanted it.

~Matt

eheuvel’s picture

@prabhakarsun: Works like a charm, thanks.

johnnydarkko’s picture

@prabhakarsun: I would like to use your solution but for some reason the "Node" option is not available Groups selection field. Does anybody else have this problem?

Here's what I've done so far:
1. I clicked on the + sign on in the relationships section.
2. Opened the groups pull down but "Node" was not an option.
3. Kept Groups at "All" option, Node: NID is not listed.

Bartezz’s picture

@#5

Brilliant, thanx for sharing!

shrop’s picture

@prabhakarsun: Thanks much. Works great! Been banging my head over this one.

ErikU’s picture

Awesome and so simple!! Thx

devkinetic’s picture

@johnnydarkko and anyone else hitting this...

There is no 'node' in the relationship section. You find 'content' and then add the node reference field you are trying to use.

Then add node:nid to your fields and select that relationship from the dropdown on the field settings screen.

skyself’s picture

@devkinetic
Thanks a lot for the explanation for us newbies.
The prabhakarsun's solution suddenly became obvious.

Kimberley_p’s picture

FileSize
40.34 KB

@m4olivei I had the same issue as you - having a nodereference field with multiple values.

I got round it another way - just in case anyone else is stuck - that is useful only if you have 3 or 4 values, otherwise the view becomes a bit cumbersome:

I added the nodereference field as a relationship 4 times (or as many as the max number in your multiple values). Then you set the delta to 1 for the first relationship, 2 for the second and so on so that each relationship corresponds to each value (image attached). Then you need to add the node id field the same number of times and assign a relationship to each.

You get a row for each value this way.

sja1’s picture

Issue summary: View changes

Hey Kimberley, thanks for sharing! I wish I had seen this a couple hours ago.

I think you meant to say you get a column for each value, rather than a row.

In my case I want a comma separated list of nids. So I used your technique and then hid all but the last nid field from display. I then enabled the rewrite the output option on the last field and used a rewrite value like [nid_1],[nid_2],[nid_3].

I had been trying to get a combination of the reference_views and views_delimited_list modules working but that route dead-ended. Your solution is very simple and works perfectly.

frederickjh’s picture

Hi!
I wanted to add a comment regarding sja1's comment #17.

I am working on a export file that requires the fields to be separated by a pipe (|). However the number of multiple values varied from record to record. So that we did not end up with extra multiple pipe delimiter characters when values were empty. I did the following:

Create a Relationship for each Delta on the node reference.

Add a Node ID field for each Delta, Exclude from display, Hide if empty, Do not rewrite if empty.

For the 2nd through the last Node ID fields rewrite the display. In the rewrite text field put the delimiter (pipe in my case) followed by the replacement pattern for the current field.

Create a Global: Custom Text field. In the Text field put the replacement patterns for all your Node NID fields.

Because fields are not rendered if they are empty the delimiters before the 2nd to the last Node ID fields also do not render.

As more sites migrate away from Drupal 6 these type of exports will be needed.
Frederick