0

I'm trying to find a way to get a view to display either field_a or field_b. For example I have to different image fields that are being rendered differently on the full node display, both of which are optional. Now I'd like to be able to show one of those pictures in my list view, either picture 1, or, if that's not present, picture 2, but never both.

Is there any smarter way to achieve this than to put the logic into a views fields template?

1 Answer 1

1

put the logic into a views fields template

If it's a "one-off", most of the time, that's the way I would have gone about it. Display the "primary" field, exclude the seconday. Template the primary to display the second as necessary.

At a recent project, I "was just going to do this once", but then the client started changing their mind, and now I have a really big mess of views templates. If I knew that I would have a lot of logic like this, I would use a Views Context display instead, pull that into Panels, and have the Page manager handle the display logic instead. More complicated, but also neater IMO, and easier to maintain, as the logic becomes independent of the presentation.

1
  • I did it with the template, as I hope this indeed occurs only once. Panels seems a little overkill in this case where all I need is an if statement. I also found a sandbox project which addresses my exact issue, it's not available for d7 yet, though: Views If Empty: drupal.org/sandbox/benclark/1213836 Mar 5, 2012 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.