It would be amazingly great and useful if there was an "As Link" (to node) for just about every field that could be displayed. This is purely for a usability issue: if I want to display a CCK field of an image to represent a node, then it should be clickable and able to take the user to the node it represents. Extra-special circumstance: if the link could be overridden for fields that take the user to other pages by default. For instance, if the Author-Image is being displayed, it defaults to going to the user profile. This is only useful in certain cases, so it would be great if there was an option to select between "To Profile" and "To Node" as appropriate. Same for Author ID, etc. I know there are ways to work around this, but this would allow a non-coding way for Administrators of Drupal sites to get extra functionality out of their configuration of Views. Small bounty/donation considered for this, feel free to contact me.

Comments

rafidr’s picture

That would be great. This is exactly what i'm looking for. Every field displayed in a view should by optional "As link".

richardroth’s picture

I agree. And looking around for a solution, it seems many other people on different parts of the site feel the same way...

richardroth’s picture

http://drupal.org/node/70380

The code at the bottom seems to be the key. I'm having a look now.

richardroth’s picture

function phptemplate_views_handle_field_VIEWNAME_node_data_field_FIELDNAME_field_FIELDNAME_value($fields, $field, $data) {
  return '<a href="/node/'.($data->nid).'">'.($data->node_data_FIELDNAME_name_field_FIELDNAME_value).'</a>';
}

Replace VIEWNAME and FIELDNAME respectively. You can get the available choices in the theme wizard. I think. Let me know what's wrong with it, as I'm not trained in this sort of thing and probably buggered the whole thing up.

markj’s picture

This works for me, in template.php. My view is called 'slc_workshops' and the CCK field I am testing on is 'field_signup_required'.

function phptemplate_views_handle_field_slc_workshops_node_data_field_signup_required_field_signup_required_value($fields, $field, $data) {
  // If 'field_signup_required' == 'Yes'
  if ($data->$field['queryname'] == 'Yes') {
    // 'event_signup' is a menu path that takes the node ID as the first argument
    return l($data->$field['queryname'], 'event_signup/' . $data->nid); 
  } else {
    // Don't render a link, just display the value, e.g., 'No'
    return $data->$field['queryname']; 
  }
}
catch’s picture

Version: 5.x-1.6-beta5 » 5.x-1.x-dev

These options are generally provided by the modules that expose information to views (see imagefield for a decent example). So best to also file issues against those modules if you think something's missing.

catch’s picture

Status: Active » Closed (won't fix)