Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Conditional Views - Sure beats Views PHP for simple variance

Parent Feed: 

Submitted by ansondparker on Thu, 03/26/2015 - 12:09

I recently had to add a new content type to an existing tabled view... the thing was that one content type had an extra field to define a link... fine.. I figured I could go in and use Views PHP.... it's a hacky solution, but a few lines and I'd be out the door... curiosity got the better of me... I know Views PHP is a bit déclassé, so for good measure I googled for a solution, and pretty quickly stumbled on Views Conditional... the documentation is clear, but I figure a few screen shots won't hurt, and may encourage the next nerd looking for a better way to set either-or's in their views...

Steps to get some variance in your views

  • Add the conditional view field after adding your fields that you want to show add the conditional view field
  • UI for Conditional View Field the UI is really straightforward - and tokens from previous rows are available.... just exclude them from view and use them here.... it's absolutely obvious :)
  • Conditional Field Outputs... Ya! and that's about it... sure - we could've done that a bunch of ways.... but with a clean UI like that there's no reason too.. and if you really want to you can have conditions based on the conditions... bonus.
Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web