views:

280

answers:

2

I have two content types, book and chapter. Each chapter node contains a node reference of the book to which it belongs. I have created a view which displays the title of each chapter for a given book. Within the view, the title field has been configured to link to its node.

All works well. I am now interested in updating the view to not display a link to a chapter's node when the chapter's body is empty. Thus this view would display a list of chapter titles for a book and link only to those chapters that have a body.

Can this be accomplished using out of the box Views functionality? If not, how would something like this be accomplished?

Thanks.

+2  A: 

I'd use the Views Custom Field module to implement your custom logic. It allows you to grab the data fetched by Views and manipulate it at will with PHP. Very handy.

ceejayoz
Thank you. Your answer provided the information that I needed to have a conditional link for the title. What I did to accomplish this was to first download and enable views_customfield. Second, I placed Title and Body fields within the view, both excluded from display. Third, within a Customfield: PHP code field I placed the following code: <?php if (strlen(trim($data->node_revisions_body)) == 0) { return $data->node_title; } else { return l($data->node_title, drupal_get_path_alias('node/' . $data->nid)); } ?>
sutch
Glad I could help. :-)
ceejayoz
A: 

I'm answering my own question because my response to ceejayoz is poorly formatted.

What I did to accomplish this was to first download and enable views_customfield. Second, I placed Title and Body fields within the view, both excluded from display. Third, within a Customfield: PHP code field I placed the following code:

<?php
if (strlen(trim($data->node_revisions_body)) == 0) {
  return $data->node_title;
} else {
return l($data->node_title, drupal_get_path_alias('node/' . $data->nid));
}
?>
sutch

related questions