1

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?

  • You can use this module Views Conditional. – SebastianT Aug 14 '19 at 8:56
  • Love it, works like a charm :) – sailormoon Aug 14 '19 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 '19 at 12:43

Browse other questions tagged or ask your own question.