How to conditionally hide a field in a drupal view?

Allain Lalonde picture Allain Lalonde · Dec 5, 2010 · Viewed 13.3k times · Source

I have two fields that I want to render but I only want the second one to display when the first one is empty. Short of overriding the field in a template file, can I do this using functionality in the built in views functionality?

Answer

atyagi picture atyagi · Jan 10, 2013

For views 3 , drupal 7

  • Desired output - Show field1 if field2 is empty.

Add both fields to view in field1, field2 order and select field1 checkbox "exclude from display".

Go to field2 and configure "Show No results behavior". Add field1 replacement pattern e.g [field1] and select "Count the number 0 as empty" , "Hide if empty" and "Hide rewriting if empty".

Now this will produce if else functionality for these two fields.