Book Image

Mastering Drupal 8 Views

By : Gregg Marshall
Book Image

Mastering Drupal 8 Views

By: Gregg Marshall

Overview of this book

Learn how to build complex displays of content—all without programming. Views were used on more than 80% of all Drupal 7 sites; now they are part of the Drupal 8 core. While most site builders and site owners are aware of views, they don't understand how to take full advantage of their power to create many amazing pages and blocks. If they use views, they might build 10 different view displays with different filters, without knowing that a contextual filter would require only a single display. Using our sample company, we'll take its existing content and evolve an ever more complex and powerful website for that company, starting with adapting the administration the user sees and moving on to making complex pages of information for site visitors. While the book is written for Drupal 8, the similarities between Views in Drupal 7 and 8 make this a useful reference for Drupal 7 site builders also.
Table of Contents (20 chapters)
Mastering Drupal 8 Views
Credits
Foreword
About the Author
Acknowledgements
About the Reviewer
www.PacktPub.com
Preface
Index

If-then-else conditional rewrites


Jim continued, "There are times when you'd like to display one of two different fields depending on some condition. Almost always, when we hear that a client wants to do something like this, we start planning on custom code to implement it. Many of these would be really hard to implement in Views, but some are of the form that if I have information in field X, then display it and otherwise display field Y. These kinds of requests can be handled within Views using the REWRITE RESULTS and NO RESULTS BEHAVIOR fieldsets."

No results options

"We haven't really covered the NO RESULTS BEHAVIOR fieldset, which looks similar to this when expanded:

No Results Behavior options

This is pretty straightforward. If a field is empty, you can create alternate values using pretty much the same tools you have for rewrite results. Now that you understand rewrite results, you know what is possible in the NO RESULTS BEHAVIOR field.

There are a couple of options beyond the alternative...