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?
This project is not covered by Drupal's security advisory policy. Hide Content Field modules provides configuration or option to hide field from form display, field exist on a form in a hidden mode. To configure to "Hide Content Field", enable this module by drush en hide_content_field or by GUI in CMS first.
There are two steps to make a field hidden in drupal 8 entity forms. You can use https://www.drupal.org/project/field_hidden and by enabling this module, Select the 'Hidden field' widget for a field in the entity type's 'Manage form display' dialogue. Save this answer. Show activity on this post.
Conditional fields allow you to manage sets of dependencies between fields. Such fields are available for editing and display only if the right condition is met. To create conditional fields, you must first create custom fields and then leverage such fields in forms.
For views 3 , drupal 7
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.
PS: Quoted option texts may be not the right ones (I'm looking at a translated site), but you get the idea.
I would normally use the views_customfield module for this kind of thing. Add a third field to your view that is a php customfield, and exclude your second field from display. You can then write a really quick PHP snippet in the customfield that checks to see if the first field is empty and prints out the second field if it is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With