Hide a Drupal Views Quick Tabs When View is Empty

Author:
phil
Created:
Sunday, March 03rd, 2013
Last Updated:
Sunday, March 03rd, 2013

Disclaimer: Accessing the information on this page means you agree to the Sites Terms of Service


If you use Drupal, I'm sure you've learned Views by now and maybe you've even added the totally awesome Quick Tabs to your arsenal of modules.

Let's say you have a quick tab setup to display tabs for several views but you want the tab to disappear if the view is empty. First off, after you create a quick tab instance, there is an option for the instance to "Hide Empty Tabs". If a view is truly empty, the tab will gracefully disappear from the tabs and your life of adding some "No results" text to the tab is greatly reduced.

But how do you do it? Some views are a little more complex and without the proper filtering, will still show data even though there's nothing to show in the view. The short answer is to make sure you have a views "filter" setup for the entity you are trying to show set to "Is not empty (NOT NULL)".

For arguments sake, I'm going to explain a very basic view. Let's say you want to show "color" in one tab and "shape" in the other so you create two fields for your content type to collect each piece of information. Next you create a view with two blocks (content panes, pages, entity reference, page... whatever floats your boat) one block is called "Color" the other is "Shape". Since these are fields, you add just the one single field to each respective block.

Next you add your normal filters like:
"content type: furry-stuff",
"Published: Yes"

And finally you need to create one more filter for each block that is a direct filter for the field you added. So let's say the field is "color", you need to add a filter for "Content: color", then set the "Operator" to Is not empty (NOT NULL). This filter basically says "show the color field as long as it isn't empty". This filter is the single most important filter you add. Without it, your views quick tab will continue to show up and force you to go bald in a matter of hours...

It should work without a contextual filter, but you'll usually get weird results on any view unless you at least add the "Content: nid" contextual filter to pretty much any node based view you have...

Save the view and go check it out!

I need to mention one thing: If you have two fields in the view, you need to rearrange the filters so the two fields are setup as an OR statement.

For example:
(Filters)
"Content Type: furry-stuff"
AND
"Content Pubished: Yes"
AND
"Content: color"
OR
"Content: shape"


There's more on this in the Quick Tabs issue queue:
http://drupal.org/node/766924#comment-3485870

Post Comment

Comments

Great thanks really very helpfull.was banging my head since last two days.

Glad it helped you out! I forget how long I spent tracking that one down but I do remember it kicked my butt enough to blog about the "workaround" fix :)

Not much has changed in the issue queue for this problem, but I believe at some point, it should be fixed in the module so we won't have to continue with the workaround.

If you're in the Wichita area, shoot me an email through the Contact page!

I was pulling my hair out trying to figure this out. Huge help! Glad it came from a fellow kansan.