I have a content type for events. There is an optional field where the user can provide a link that overrides the default link to the event.

For all of our internal events, the link should take website users to the node of the event. However, for events that are held elsewhere by third parties, the link should take the website user to whatever external link is official for that event.

I'm having difficulty creating a single link field in a view that is the value of the external link, unless there no value, in which case it falls back to the node link.

I can make a re-written field that is [override_link][path], but that always shows the path, no matter what. I only want the path when there is no override_link value.

This is in a Drupal 7 site.

2 Answers 2


The easiest way IMO to do this is to use the views field template. Here is a very detailed and helpful tutorial on DO. You can find the field template's name in the views theming tab under the advanced tab.

In terms of implementation for your use-case, the field's $output in the template would be empty if there is no link, and then you can change $output to be the link to that node (which you should be able to access with $row->nid).


I don't think this is the best solution, so becarefull. I always use Views PHP. This module adds a "Global PHP field" in the views fields, where yo can use PHP to return the value that you need. In this Global PHP field, you will have access to data of others fields as an array in $data variable.

Check this.

Hope this help.

  • It is dangerous to use Views PHP, if you have a bug in your PHP it can be very hard to track down and could even make your site unusable or require tracking down php code in the database. As the module image also suggests, it's bad for performance too since this it is not cached.
    – wranvaud
    Oct 12, 2017 at 0:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.