English 中文(简体)
Conditional link to node within views?
原标题:

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.

最佳回答

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.

问题回答

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));
}
?>

There s also this clever workaround which allows you to achieve this very easily:

  1. Add 2 title fields one with link and one with no link, and make both them exclude from display.
  2. Add body field,
  3. In No result behavior put title with no link replacement token to it.
  4. In Rewrite results behavior put title with link replacement token to it.
  5. Tick hide if empty.

Source





相关问题
Drupal Multi-language: Simple strings not translated

I m adding additional languages to a Drupal site that I m building. Getting the translation of content working is fairly easy using the Internationalisation module. Yet, simple things such as date ...

Setting up a WYSIWYG editor for Drupal site users [closed]

Looking through the Drupal contrib modules, and after a few Google searches, it becomes evident that there are any number of choices and combos available to set up a WYSIWYG editor in Drupal. I m ...

Change size of user/password login box

I don t know how to change the size of the login username/password boxes on the drupal site that I m trying to build. I m stumbling through the theming, and don t know where to find the file that ...

How does Drupal provide an edit/review/publish model?

How does Drupal support a means to update and review a website before it is published? Does it only allow you to preview a page at a time before you publish it or is there a way to create a site ...

Term for rotating header

I m looking for terminology that describes this behavior: The header of a web-page contains a different image every time you visit it. Update: It is not an advertisement, but images related to the ...

Has anyone checked out Drupal 7? [closed]

Has anyone checked out a copy of Drupal 7 yet? What do people think? I m pretty excited about the PDO and all of the designers I work with a very excited about the new admin interface/structure. Do ...

热门标签