I have a view which displays nodes of content type "news", which has two fields: f_one and f_two. What I want is:

  • If f_one has content and f_two is empty, display only f_one
  • If f_one is empty and f_two has content, I want to display only f_two

That's easy: I just click both the fields in the view settings to display them. When any of them has content they are displaying. But what if I want to display only f_one when f_one has content and f_two has content? How can I do it?

In this way both fields are displaying, but I want only f_one. I guess I could use filters but I don't know how. Should I use some global variables?

closed as too broad by kiamlaluno Aug 14 at 10:24

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • You can use this module Views Conditional. – SebastianT Aug 14 at 8:56
  • Love it, works like a charm :) – sailormoon Aug 14 at 9:05
  • You could also do it with Rewrite Results on the first field. Make sure the second field is ordered before on the field list, Exclude it from display, then edit the first field settings to enable the Rewrite, use logic in twig to display the first field value unless it's empty, in which case you show the second field value. – prkos Aug 14 at 12:43

Browse other questions tagged or ask your own question.