How can I make one field show up, unless it has no value, in which case another field is shown? I want to do this on the default node view, I already know how to accomplish it in views. I'm assuming it will mean coding something in my theme, but where best to do that is a little confusing to me.
1 Answer
I would checkout Field formatter conditions where you can set a whole variety of conditions of one field based on if another field is empty or not. You would set these conditions in whatever display mode you are in so in the case of a node, most likely the view mode will be full or default. (e.g. admin/structure/types/manage/[MY_content_type]/display
Alternatively, you could do some custom node template theming and set conditions there such as if one field is not empty do this, else, show the other field.
<?php if (!empty($content['field_foo'])): ?>
<?php print render($content['field_foo']); ?>
<?php else: ?>
<?php print render($content['field_bar']); ?>
<?php endif; ?>
This assumes there is a value with field_bar so you may need to add conditions for that field too if it's empty. With per field theming, you may need to not render the general content variable as well, it just depends on the order and where things fall in the template.
-
Thanks that module looks promising and the code based approach is what I was looking for, though now that I see it I kick myself for not figuring it out myself.– UltraBobCommented Feb 17, 2016 at 23:51
-