I have created a View with four fields. One of these fields is a CCK field. I need in this View for that field to be a clickable link to the node. However it appears that Views only allows Node:Title to be used as a link to the node. Is this correct?

I am using

CCK 5.x-1.10
Views 5.x-1.6

Comments

lsommerer’s picture

I needed to do this a few weeks ago and I used the Computed Field CCK module.

You create a new (computed) field that will hold the "clickable" version of the URL, setup the computation bit (there are examples) and then display this field instead of the original in your view. Here's the code I used to compute my field:

//create the url based on the username field
$url= 'http://sites.lincolnlutheran.org/'.$node->field_username[0]['value'];
// turn the url into an html link
$link= l($url,$url);
// store the data in our computed field if necessary
// some teachers don't have websites, so we don't store
// anything for them.
if ($node->field_staffbio_display_website[0]['value'] == 1)
  $node_field[0]['value'] = $link;
else
  $node_field[0]['value'] = '';

It's certainly possible that there's another way to do this, so you might want to wait for other responses or for someone with more experience to say this is a good approach.

stevenpatz’s picture

I'll try this first thing tomorrow morning.

stevenpatz’s picture

I have this as my computed value:

//I grab the NID of the node
$url= 'http://localhost/'.$node->nid;
// turn the url into an html link
$link= l($url,$url);
// store the data in our computed field if necessary
// If the headline is blank, don't store anything.
if ($node->field_headline[0]['value'] == 1)
  $node_field[0]['value'] = $link;
else
  $node_field[0]['value'] = '';

I edit my View and am able to pick as one of the fields the computed value ( I called it HeadlineLink) I save my View and then go view it. Instead of a clickable link though all I have is n/a in plain text. Did I miss a step? Is the computed value code not right? I think I have the logic of the code correct. It creates a link and saves it as $link and then it sets $node_field[0]['value'] to that value.

Do I need to do something else?

stevenpatz’s picture

This is what I had to do:

if (!$node->nid) node_save($node);
$url= 'http://localhost/node/'.$node->nid;
$text_link = $node->field_headline[0]['value'];
$linky = l($text_link,$url);
$node_field[0]['value'] = $linky;

I was missing the node_save, and in your example the
if ($node->field_staffbio_display_website[0]['value'] == 1)
block was always false, that was why I was getting 'n/a'.

Thanks so much for the help.