Hide my block view if CCK field is empty

Let's say you have a CCK Imagefield you'd like displayed in a sidebar instead of the main $content area of your page. You can check exclude under Display Fields for that content type, and then use Views to pull out the field and stick in a block display, but if your node does not contain an image, you may notice that a few empty <div> tags are returned, and your theme might not be too friendly in this case. Now you need to find some way to hide that view if the field is empty...

Why not try adding a filter to the View?

In this case I'm assuming you've used Views' Arguments to look for a "Node: Nid", and the "Node ID from URL" is selected as the option for "Provide default argument". Since you're on a node/[nid] page, there is a node returned, even if it has empty fields.

Under Filters, add a filter for the field (probably just one, to be safe) in question. Many fields will have an "is not empty (NULL)" option. This probably won't work for all field types.

Provided you have not filled in any empty text for your view, I think this takes care of it. Block views that have zero rows will not appear, but results with empty fields are still results.


Thanks for the tip... I struggled with this for several hours before finding this answer which worked like a charm.

Submitted by Guest (not verified) on Fri, 09/09/2011 - 13:35

Man, you are Genius! Thanks a lot!

Submitted by Guest (not verified) on Sun, 10/16/2011 - 10:12


Submitted by Guest (not verified) on Fri, 12/02/2011 - 10:18

You just saved my day. I was going around this issue for couple of hours not knowing why the hell views keeps rendering an empty block when it shouldn't create the block in the first place.

Adding the filter did the trick.

Submitted by Guest (not verified) on Fri, 09/21/2012 - 01:39

Sign up to receive email notifications of whenever we publish a new blog post or quicktip!